Work on a small multithread Server .My Server run properly,Create a Listen thread and for every Client create a WorkThread .In Workthread there is a loop to recv Data .Able to run few Clients.
When send Data from the Clients to Server receive correctly
Want to know how can use Form with the workThread ....
thanks for the time
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"
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
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.
Bookmarks