TCP socket listen only question
Posted on 2013-10-29
I am attempting to receive data via a socket. The data is sent maybe once a second but there can also be long (as in hours) delays between messages. My code "works" but it sometimes hangs on the .Receive method. Any suggestions on how I can listen to this connection without a hangup? See code below....
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bytes(1024) As Byte
Dim bytesrec As Integer
Dim ipaddress As IPAddress = ipaddress.Parse("192.168.10.20")
Dim remoteEP As New IPEndPoint(ipaddress, "23")
Dim sendreq As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Do While True
bytesrec = sendreq.Receive(bytes) ' Here is where it hangs sometimes
If bytesrec > 0 Then
'do something here.......
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load