Board index » Visual Studio » Socket.Receive hangs
|
Jlorga
|
Socket.Receive hangs
Visual Studio40
Hi all, I am currently working on a small application that sends messages from a client to a server and receives messages in return. Basically the functionality is made with sockets which is working just fine except of one little thing. whenever the client tries to receive a message the server has sent it goes into a hang. unfortunately without an error or exception at all. the communication itself (sending message from client to server, server listens on port and receives message, server sends message) is doing its job so I cannot explain to myself why the socket.receive won't work for the client (it does on the server side obviously). but lets dig into some code: CLIENT connecting the server: _Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim oServerIP As System.Net.IPAddress = System.Net.IPAddress.Parse(sServerIP) Dim oRemoteEndPoint As New System.Net.IPEndPoint(oServerIP, iPort) _Socket.Connect(oRemoteEndPoint) sending message: Dim oData As Object = sMessage Dim bytData() As Byte = System.Text.Encoding.ASCII.GetBytes(oData.ToString) _Socket.Send(bytData) receiving message: Dim bytBuffer(1024) As Byte ===>Dim iReceived As Integer = _Socket.Receive(bytBuffer) Dim charChars(iReceived) As Char Dim oDecoder As System.Text.Decoder = System.Text.Encoding.UTF8.GetDecoder Dim iCharLength As Integer = oDecoder.GetChars(bytBuffer, 0, iReceived, charChars, 0) Dim sData As New String(charChars) SERVER on client connect: _SocketWorker = _SocketListener.EndAccept(AsyncResult) '_SocketListener is bound to local IP and listens to same port as client sending message to client: Dim oData As Object = sMessage Dim bytData() As Byte = System.Text.Encoding.ASCII.GetBytes(oData.ToString) _SocketWorker.Send(bytData) Has anyone an idea why the Socket.Receive on the client side is not doing the expected job ? it simply runs into a hang and the program itself is not responding anymore. thanks a lot for your hints! Joe. - |
