我有以下代码:
try { mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, serverPort); mainSocket.Bind(ipEndPoint); mainSocket.Listen(MAX_CONNECTIONS); mainSocket.BeginAccept(new AsyncCallback(serverEndAccept), mainSocket); OnNetworkEvents eventArgs = new OnNetworkEvents(true, "Listening for Connection"); OnUpdateNetworkStatusMessage(this, eventArgs); } catch (SocketException e) { // add code here } catch (ObjectDisposedException e) { // add code here }
如果SocketException
服务器一直在成功监听,我该如何测试代码呢?
不要对实时网络进行测试.模拟套接字并测试一个抛出一个的模拟器SocketException
.