S
scarleton
I am writing a .NET 2.0 client application uses sockets to communicate
with a firmware on an instrument. The client needs to be able to
recover from a lost connection to the instrument. While trying to send
data to the instrument, after a disconnect/reconnect the socket throws
a exception with the following error: WSAECONNRESET (10054)
The flow is:
1: Open connection
2: send packet
3: receive packet
<Repeat 2 & 3 numerous times>
4: Diconnect
5: Reconnect
6: send
< WSAECONNRESET (10054)> exception!
If the client is closed and restarted, all works well, so I am
confident that the problem can be fixed on the client side, not the
firmware/instrument side of things. Here is some code snippets:
On Connect:
-----------
if (s == null) {
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.IP);
}
s.BeginConnect(this.endPoint, new
AsyncCallback(this.AsynchConnectCallback), s);
In AsynchConnectCallback:
-------------------------
Socket s = ar.AsyncState as Socket;
try {
s.EndConnect(ar);
// Setup some threads for reading/writing
}
catch (SocketException se) {
DumpException("AsynchConnectCallback", se);
}
On Disconnect:
with a firmware on an instrument. The client needs to be able to
recover from a lost connection to the instrument. While trying to send
data to the instrument, after a disconnect/reconnect the socket throws
a exception with the following error: WSAECONNRESET (10054)
The flow is:
1: Open connection
2: send packet
3: receive packet
<Repeat 2 & 3 numerous times>
4: Diconnect
5: Reconnect
6: send
< WSAECONNRESET (10054)> exception!
If the client is closed and restarted, all works well, so I am
confident that the problem can be fixed on the client side, not the
firmware/instrument side of things. Here is some code snippets:
On Connect:
-----------
if (s == null) {
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.IP);
}
s.BeginConnect(this.endPoint, new
AsyncCallback(this.AsynchConnectCallback), s);
In AsynchConnectCallback:
-------------------------
Socket s = ar.AsyncState as Socket;
try {
s.EndConnect(ar);
// Setup some threads for reading/writing
}
catch (SocketException se) {
DumpException("AsynchConnectCallback", se);
}
On Disconnect: