M
Marty
Hi,
I hope you can help me with this one (my code is below my message).
I have many clients connecting to my server. When any of them
disconnect, something happen.
This user get disconnect from the server and this is fine. But
sometime, I can't reproduce exactly the situation (maybe the client
crashed), the related socket in server seems to get nuts and still think
that it is connected to the client.
Here is my part of the code that contain a possible bug... The socket
keep calling rcvSocketMessages() to infinity. It receive an empty ""
character in strTempMesg.
What I don't understand, it is why is pass through the first and second
"if" that concern the mySocket state. Should it be able to detect that
the client is no more there?
Do you have any idea why the mySocket keep its connected state?
I hope my explanation was clear, otherwise, ask me and I'll answer your
question. I really have to correct this problem.
Thank you very much.
Marty
Private mySocket As Socket
Private Sub rcvSocketMessages(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String
If (Not mySocket Is Nothing) Then
If (mySocket.Connected) Then
BytesRead = CurSocket.EndReceive(ar)
strTempMesg = Encoding.ASCII.GetString(Buffer, 0, BytesRead)
'Do something with strTempMsg
CurSocket.BeginReceive(Buffer, 0, READ_BUFFER_SIZE,
SocketFlags.None, AddressOf rcvSocketMessages, Nothing)
Else
forceSocketDisconnection()
End If
Else
'forceSocketDisconnection()
End If
Catch e As Exception
'catch error
End Try
I hope you can help me with this one (my code is below my message).
I have many clients connecting to my server. When any of them
disconnect, something happen.
This user get disconnect from the server and this is fine. But
sometime, I can't reproduce exactly the situation (maybe the client
crashed), the related socket in server seems to get nuts and still think
that it is connected to the client.
Here is my part of the code that contain a possible bug... The socket
keep calling rcvSocketMessages() to infinity. It receive an empty ""
character in strTempMesg.
What I don't understand, it is why is pass through the first and second
"if" that concern the mySocket state. Should it be able to detect that
the client is no more there?
Do you have any idea why the mySocket keep its connected state?
I hope my explanation was clear, otherwise, ask me and I'll answer your
question. I really have to correct this problem.
Thank you very much.
Marty
Private mySocket As Socket
Private Sub rcvSocketMessages(ByVal ar As IAsyncResult)
Try
Dim BytesRead As Integer
Dim strTempMesg As String
If (Not mySocket Is Nothing) Then
If (mySocket.Connected) Then
BytesRead = CurSocket.EndReceive(ar)
strTempMesg = Encoding.ASCII.GetString(Buffer, 0, BytesRead)
'Do something with strTempMsg
CurSocket.BeginReceive(Buffer, 0, READ_BUFFER_SIZE,
SocketFlags.None, AddressOf rcvSocketMessages, Nothing)
Else
forceSocketDisconnection()
End If
Else
'forceSocketDisconnection()
End If
Catch e As Exception
'catch error
End Try