Re: Multithreading Socket
In VB6? You'd have to post some of your code for us to even begin to help.
Also, your question isn't clear
Re: Multithreading Socket
In VB6? You'd have to post some of your code for us to even begin to help.
Also, your question isn't clear
Yesterday 08:32 PM
Good afternoon
Yes my friend dglienna small multithread in vb 6.
Here the ThreadListen and Workthread code to saw u how work with thread.
code
Public Function ThreadListen(ByVal Param As Long) As Long
ThreadInit.InitThread
Dim ClientID As Long
Dim sAddr As sockaddr_in
Dim sAddrLen As Long
Dim IP As String
TID = GetCurrentThreadId
Lthread = TID
listen hListenSck, 10
Do While True
sAddrLen = 16
nRet = accept(hListenSck, sAddr, sAddrLen)
If nRet <> SOCKET_ERROR Then
ClientCount = ClientCount + 1
SockStoreList.Add nRet
Frmain.thlabel.Caption = ClientCount
Add_ListData nRet, "127.0.0.1"
End If
ClientStore(ClientCount).sock_ID = nRet
Thread.SetThreadFunc AddressOf WorkthreadTest, 0
'Through the "thread Param" to pass parameters
Thread.StartThread ClientCount
Loop
End Function
--Workthread-------
Public Function WorkthreadTest(ByVal Param As Long) As Long
ThreadInit.InitThread
Dim DBuff As String
Dim ReadBuff As String
Dim sRec As Long
TID = GetCurrentThreadId
Add_DataClientStore Param, nRet, TID
ThreadList.Add TID
WriteLog "Client Connected : Socket ID " & nRet & " On Thread ID:" & TID
Do While True
DBuff = Space(4096)
sRec = recv(ClientStore(Param).sock_ID, ByVal DBuff, Len(DBuff), 0)
If sRec <> 0 And sRec <> SOCKET_ERROR Then
ReadBuff = ReadBuff & Left(DBuff, sRec)
WriteData ReadBuff & " " & "Test Hello hello"
WriteData "Data Received.:" & ReadBuff & " Socket ID..." & ClientStore(Param).sock_ID
End If
Loop
End Function
Code
When Click on command(Listen)on FormMain Star a Thread (ThreadListen)to listen for Connections .
When a client arrive just pass the SocketID to a New Thread(Workthread)
In this thread run a loop to receive data .
Until here make many testings and can say able to run 10 Clients(10 threads)
If the Main form have a second Form(data)how can run this form and communicate with Workthread ?
Or Just receive on workthread and the Sending on Data form ..
thanks for the time
Re: Multithreading Socket
Pretty complicated in VB6. I'd switch to VB.Net, where it should be a little simpler to test.
Re: Multithreading Socket
Thankd for the time
Doesnt matter wil try again
Re: Multithreading Socket
I can't tell much about what you are doing from the code posted but I can tell you that I have written a working server in VB6 that handles up to 25 connections without using threading and it works very well.