-
January 16th, 2012, 03:32 PM
#1
Multithreading Socket
Good evening
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
p.s sorry for my bad English
-
January 16th, 2012, 06:22 PM
#2
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
-
January 17th, 2012, 01:22 PM
#3
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
-
January 17th, 2012, 01:25 PM
#4
Re: Multithreading Socket
Pretty complicated in VB6. I'd switch to VB.Net, where it should be a little simpler to test.
-
January 17th, 2012, 01:36 PM
#5
Re: Multithreading Socket
Thankd for the time
Doesnt matter wil try again
-
January 17th, 2012, 02:01 PM
#6
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.
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|