B
Benjamin Lukner
Hi!
I have a nasty problem concerning a TCP/IP connection:
I use a System.Net.Sockets.Socket and BeginSend/EndSend in my program.
When WLAN still works fine but the connection to the server is broken
anyway (LAN cable plugged out, switch failure or a firewall killed the
connection because of a time out while the PPC2003 was in suspend mode),
the program doesn't recognize it.
For a test I use a timer sending some data to the server every second.
I can plug out the server's LAN connection and my program keeps on
sending data without getting an error! But it's a TCP and not a UDP
connection!?!
Feature or failure...?
This is some of my code:
Private _socket As Socket
[...]
_socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
_socket.Blocking = False
_socket.BeginConnect(endPoint, AddressOf ConnectCallback, Nothing)
[...]
Friend Function Send(ByVal data() As Byte) As Boolean
Try
If _socket Is Nothing Then
Return False
End If
If _socket.Connected = False Then
Return False
End If
Try
If _socket.Poll(1, System.Net.Sockets.SelectMode.SelectError) _
= True Then
Return False
Else
If _socket.Poll(1, System.Net.Sockets.SelectMode.SelectWrite) _
= False Then
Return False
End IF
Catch
Return False
End Try
Catch
Return False
End Try
_socket.BeginSend(data, 0, data.Length, _
SocketFlags.None, AddressOf SendCallback, Nothing)
Return True
End Function
[...]
Private Sub SendCallback(ByVal ar As IAsyncResult)
If _socket.EndSend(ar) < 1 Then
Debug.WriteLine("Nothing sent.")
End If
End Sub
I also tried to Set SendTimeout and ReceiveTimeout, but without effect.
What else could I do to recognize the closed connection?
Kind regards,
Benjamin Lukner
I have a nasty problem concerning a TCP/IP connection:
I use a System.Net.Sockets.Socket and BeginSend/EndSend in my program.
When WLAN still works fine but the connection to the server is broken
anyway (LAN cable plugged out, switch failure or a firewall killed the
connection because of a time out while the PPC2003 was in suspend mode),
the program doesn't recognize it.
For a test I use a timer sending some data to the server every second.
I can plug out the server's LAN connection and my program keeps on
sending data without getting an error! But it's a TCP and not a UDP
connection!?!
Feature or failure...?
This is some of my code:
Private _socket As Socket
[...]
_socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
_socket.Blocking = False
_socket.BeginConnect(endPoint, AddressOf ConnectCallback, Nothing)
[...]
Friend Function Send(ByVal data() As Byte) As Boolean
Try
If _socket Is Nothing Then
Return False
End If
If _socket.Connected = False Then
Return False
End If
Try
If _socket.Poll(1, System.Net.Sockets.SelectMode.SelectError) _
= True Then
Return False
Else
If _socket.Poll(1, System.Net.Sockets.SelectMode.SelectWrite) _
= False Then
Return False
End IF
Catch
Return False
End Try
Catch
Return False
End Try
_socket.BeginSend(data, 0, data.Length, _
SocketFlags.None, AddressOf SendCallback, Nothing)
Return True
End Function
[...]
Private Sub SendCallback(ByVal ar As IAsyncResult)
If _socket.EndSend(ar) < 1 Then
Debug.WriteLine("Nothing sent.")
End If
End Sub
I also tried to Set SendTimeout and ReceiveTimeout, but without effect.
What else could I do to recognize the closed connection?
Kind regards,
Benjamin Lukner