Socket Retreive
-
I have an application that retrieves data from a socket. The process is periodically not returning any results. I have tried the following methods for connecting to the socket in an attempt to resolve the issue but have been unsuccessful. Is this a problem in my code or is it related to network issues? What can be done to better track this issue and resolved it? Code Option #1
Dim Client As System.Net.Sockets.TcpClient Dim netStream As NetworkStream ''// SETUP CONNECTION Client = New System.Net.Sockets.TcpClient Client.NoDelay = False Client.Connect(Switch.IPAddress, Switch.Port) netStream = Client.GetStream() ''// Read Buffer Do numberOfBytesRead = netStream.Read(bytes, 0, uCVT.IntNulls(Client.ReceiveBufferSize)) Loop While netStream.DataAvailable ''// Close If Not netStream Is Nothing Then netStream.Close() If Not Client Is Nothing Then Client.Close()
Code Option #2Dim Socket As Socket ''// SETUP CONNECTION Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim rEP As New IPEndPoint(IPAddress.Parse(Switch.IPAddress), Switch.Port) Socket.Connect(rEP) ''// Read Buffer Dim bytes(1024) As Byte Dim bytesRec As Integer = Socket.Receive(bytes, 0, Socket.Available, Net.Sockets.SocketFlags.None) ''// Close If Not Socket Is Nothing Then Socket.Close()
Thank you, Jason W.