Since TCPClient in VB2005 does not implement data_received event like Winsock, how can I program an event routine to handle data_received event? Thanks.
event of receive data on net work
Collapse
X
-
Here is the piece of code which is running inside thread, not sure where to put thread.sleep(), how can it save CPU time. Thanks
Public Sub start()
Dim stream As NetworkStream
Dim st As Boolean
Dim cmd, parm As String
Dim len, index As Integer
Dim s As String = Nothing
stream = Client.GetStrea m()
Do
st = stream.DataAvai lable
If (st = True) Then
Dim bytes(Client.Re ceiveBufferSize ) As Byte
stream.Read(byt es, 0, CInt(Client.Rec eiveBufferSize) )
s = Encoding.ASCII. GetString(bytes )
len = s.Length
index = s.IndexOf(":")
If index < 0 Then
Exit Sub
End If
'example CARD:1234567$
cmd = s.Remove(index, len - index) 'keep CARD as cmd
parm = s.Remove(0, index + 1) 'remove CARD:
index = parm.IndexOf("$ ")
Try
parm = parm.Remove(ind ex, parm.Length - index)
Catch ex As Exception
End Try
stn.ProcRXCmd(c md, parm)
End If
Loop
End SubComment
-
I think that I had figured out, just put the sleep() in side the Do-Loop. It works
In my application, I use TCPClient to connect to multiple device, each device will have one thread running in my application to handle all activities asociate with that device, each device will send information to my application. My question is: If the info from all device come at the same time, will any data or string be lost, does TCPIP protocol take care and guarantee the traffic? Any setting needed for network to optimize the traffic?
ThanksComment
Comment