-
1, the classic error can not access the freed objects. Object name: "System.Net.Sockets.Socket"
-
-
- (1), Problem scene
-
(2), problem narration
Somewhere in the program called after the Socket.close, the socket is also called, the above error!
(3). Solution
Use the following sentence:
if (stsend! = null && stsend. Connected)
Stsend! = null: This sentence will be invalid after socket.close, because all of its connected resources have been released when the socket connection is closed, so it should be used with connected;
Stsend. Connected: Gets a value that indicates whether the last operation of the socket was send or receive as a connection to the remote host, and if not, it was disconnected.
Extension Description:
All unmanaged resource programmers must be able to control the release of resources, such as database connections, socket connections, etc. should be shown off after use, if it is a long connection, you should ensure that all occupied connections are closed when the program exits.
2. Classic error "The remote host forced the shutdown of an existing connection. "
(1) Problem site
(2), problem narration
For example, the classic problem with the network, because it is the server and the client of either side of the active disconnection, causing the "remote host forced to shut down a now connected" exception. This situation causes the program to prompt for an exception and cannot continue execution down.
(3). Solution
By exception handling, through the exception to indicate that the network is not normal, and thus jump out of the program branch, not because of abnormal problem program paralysis!
Such as A catch to this kind of System.Net.Sockets.SocketException exception (of course, it is set to Exceptioin exception, grab a wider range), then use the MessageBox to give the user a hint, and then exit from the branch on the line.
This article is quoted from: http://blog.chinaunix.net/uid-25498312-id-3321852.html
C#socket Communication two most classic error solutions