Issue with socket vb.net during beginreceive of clients from server send

  • Thread starter Thread starter _Genko_
  • Start date Start date
G

_Genko_

Guest
Hi,
I've created a client / server application that provides almost constant communication between N clients and a server.
I state that I have created a home network in which a server communicates with two clients via routers connected with RJ45 cable and one instead via wifi.
The three clients have Windows 10 64 bit operating system, the server is a 32 bit professional Windows XP.

The architecture seems to hold until the server has to communicate with two clients, but when I connect the third and the request for data increases towards the server (for example image file type) one of the two clients connected via RJ45 goes into error with this signal:

System.Net.Sockets.SocketException (0x80004005): Socket closed in the direction specified by a previous stop call. Request to send or receive data canceled
in System.Net.Sockets.Socket.BeginReceive (Byte [] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state)

this is the process of receiving data by the three clients:

While (True)
Try
SyncLock UR_manager

If SocketConnected (clientSocket_UR.workSocket_UR) Then
clientSocket_UR.workSocket_UR.BeginReceive (clientSocket_UR.buffer_UR, 0, ClientState.BufferSize_UR, 0, New AsyncCallback (AddressOf ReceiveServerRequest_UR), clientSocket_UR)
RequestReceivedAndElaborated_UR ", clientSocket_UR.IdentificationCode)
RequestReceivedAndElaborated_UR.WaitOne ()
else
Exit While
End If
End SyncLock
Catch ex As Exception
MsgBox (ex.ToString)
End Try
End While



The Asyncallback process is as follows

Dim clientConnected_UR As ClientState = CType (ar.AsyncState, ClientState)
Try
clientConnected_UR.HasClientReceivedResponse_UR = False
Dim clientHandler_UR As Socket = clientConnected_UR.workSocket_UR
clientHandler_UR.ReceiveBufferSize = ClientState.BufferSize_UR

Dim errorCode As SocketError
'Read data from the client socket.
Dim bytesRead As Integer = clientHandler_UR.EndReceive (ar, errorCode)

If errorCode <> SocketError.Success Then
bytesRead = 0
End If

If bytesRead> 0 Then

Process do reading

end if


Catch ex As Exception

End Try

this is the server side

While (True)
Try
If clientSocketUR.workSocket.Connected Then

Dim actualThread As Thread = CType (Threading.Thread.CurrentThread, Thread)

clientSocketUR.Databuffer = Nothing
clientSocketUR.workSocket.BeginReceive (clientSocketUR.buffer, 0, ClientState.BufferSize, 0, New AsyncCallback (AddressOf UR_manager), clientSocketUR)
clientSocketUR.RequestReceived_UR.WaitOne ()
End If
If Not clientSocketUR.workSocket.Connected Then
Dim clientSocket_UR = CType (clientsList_UR ("ID_" & clientSocketUR.id_user), ClientState)
Server.DropClientConnections (clientSocketUR)
Exit While
End If
Catch ex As Exception
MsgBox (ex.ToString)

End Try
End While



Thanks in advance for the help.

Continue reading...
 
Back
Top