Private Sub tmrSend_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrSend.Tick
bElapsed = True
End Sub
Private Sub SendData(sMsg as string)
Try
Dim tcp As New TcpClient
TCP.Connect(curLab.IPAddress, curLab.IPPort)
TCP.NoDelay = True
Dim stream As NetworkStream = TCP.GetStream()
Dim data As [Byte]()
'Convert sMsg to byte array Data to send to stream
data = StrToByteArray(sMsg)
stream.Write(data, 0, data.Length)
Thread.Sleep(0) 'what does the thread do and why does it need to be stopped?
If curLab.WaitforACKnowledgement Then
tmrSend.Enabled = True
'tmrSend.Start() - started above
bElapsed = False
sReply = ""
Do Until bElapsed = True Or stream.DataAvailable = True
Application.DoEvents
Loop
If stream.DataAvailable Then
Dim lenReply As Integer, iOffset As Integer, iSize As Integer
iSize = 1024
Dim strReply(iSize) As Byte
lenReply = 1
Do Until lenReply = 0
lenReply = stream.Read(strReply, iOffset, iSize)
sReply = sReply & ByteArrayToString(strReply)
If lenReply > iSize Then
iOffset = iOffset + lenReply
Else
Exit Do 'this worries me but it may be alright
End If
Loop
stream.Close()
End If
Thread.Sleep(0) 'didn't we already do this?
End If
tmrSend.Stop() 'I'd prefer this to be done on the timer tick to prevent further calls on it and replaced here with Timer.Enabled=False
stream.Close(500)
tcp.Close()
bDataSent = True
end sub