I try to make a Multithread socket .I pass the AcceptHandler in a new thread and Succesfully Workthread Start .
The socket By Default is Blocking mode
In blocking Mode Create Threads and can Send data to the Last Socket Successfully
If go to Set The Socket in NoBlocking Mode
Código:
Dim NonBlock As Long
NonBlock = 1
If ioctlsocket (nRet, FIONBIO, NonBlock) = SOCKET_ERROR Then
WriteLog "Socket Cannot Set NoBlocking"
End If
My Workthread
Código:
Public Function Workthread (ByVal Param As Long) As Long
Const MAX_BUFFER_LENGTH As Long = 8192 'Normal = 8192' MAX = 65536
Dim Buffa (1 To MAX_BUFFER_LENGTH) As Byte
Dim dBuff As String
Dim ReadBuff As String
Dim sRec As Long
tID = GetCurrentThreadId
Add_DataClientStore ClientCount, nRet, tID''/ / Store Data in a public type (sockid, threadid)
WriteLog "New Client Arrive with Socket ID" & nRet & "On Thread ID:" & tID''/ / write data to listbox
Do''While True
ClientStore (ClientCount). Sock_ID = nRet
sRec = recv (ClientStore (ClientCount). Sock_ID, Buffa (1), MAX_BUFFER_LENGTH, 0 &)
ReadBuff = StrConv (Buffa, vbUnicode)
[b]dBuff = Left $ (ReadBuff, sRec) [/b]
WriteLog "Data Received.:" & DBuff & "Socket ID ..." & ClientStore (ClientCount). Sock_ID
End If
Loop
End Function
The line to Crash is
dBuff = Left$(ReadBuff, sRec)
If Someone know anything
Thanks for the time
p.s Attach a ScreenShot with 505 Threads
2:The Main thread and the Listenthread
503 :Clients
cpu usage =100%
This is the Error
http://i54.tinypic.com/11qh94w.jpg
thanks for the time
Good night