I've pinched some code from the msdn website for tcp client class.
But it's not quite doing what I want it to do, I've played around with it to get it to pretty much work. but every 2nd job it receives it simply misses information, or doesn't get picked up at all.
When I do it locally on the computer, it works fine, but it seems doing it over the network it hits issues.
Is there anyway within this tcp class that there can be a check in place to make sure all information has been received from the sender?
Maybe there is a better way to write what I have done? I have thought about separating the tcp class into 2 separate functions. One that accepts the client, and then one that receives the information. Perhaps this is the go? I'll just need to learn how to use events etc.
Private Sub tcp()
Dim server As TcpListener
server = Nothing
Do
Try
Dim port As Int32 = 22490
Dim localAddr As IPAddress = IPAddress.Parse("192.168.1.100")
server = New TcpListener(localAddr, port)
Dim bytes(1024) As Byte
Dim data As String = Nothing
server.Start()
While True
Dim client As TcpClient = server.AcceptTcpClient()
Sleep(2000)
data = Nothing
Dim stream As NetworkStream = client.GetStream()
Dim i As Int32
i = stream.Read(bytes, 0, bytes.Length)
While (i <> 0)
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data)
stream.Write(msg, 0, msg.Length)
datastring = data
txtboxcreate(datastring, currenttb)
i = 0
End While
client.Close()
End While
Catch e As SocketException
Finally
server.Stop()
End Try
Loop
End Sub