Creates a TcpListener and connects a Socket to it. It stores the two TcpClient on the object: the local to the listener and the remote one. Very useful for unittesting components that requires sockets.
コード例 #1
0
ファイル: TcpTestServer.cs プロジェクト: ktj007/smrr-server
 public static TcpTestServer Create()
 {
     var TcpTestServer = new TcpTestServer();
     {
         var BindIp = "127.0.0.1";
         var BindPort = NetworkUtilities.GetAvailableTcpPort();
         TcpTestServer.TcpListener = new TcpListener(IPAddress.Parse(BindIp), BindPort);
         TcpTestServer.TcpListener.Start();
         var Event = new ManualResetEvent(false);
         TcpTestServer.TcpListener.BeginAcceptTcpClient((AsyncResult) =>
         {
             TcpTestServer.LocalTcpClient = TcpTestServer.TcpListener.EndAcceptTcpClient(AsyncResult);
             Event.Set();
         }, null);
         TcpTestServer.RemoteTcpClient = new TcpClient(BindIp, BindPort);
         Event.WaitOne();
     }
     return TcpTestServer;
 }
コード例 #2
0
        static public TcpTestServer Create()
        {
            var TcpTestServer = new TcpTestServer();

            {
                var BindIp   = "127.0.0.1";
                var BindPort = NetworkUtilities.GetAvailableTcpPort();
                TcpTestServer.TcpListener = new TcpListener(IPAddress.Parse(BindIp), BindPort);
                TcpTestServer.TcpListener.Start();
                var Event = new ManualResetEvent(false);
                TcpTestServer.TcpListener.BeginAcceptTcpClient((AsyncResult) =>
                {
                    TcpTestServer.LocalTcpClient = TcpTestServer.TcpListener.EndAcceptTcpClient(AsyncResult);
                    Event.Set();
                }, null);
                TcpTestServer.RemoteTcpClient = new TcpClient(BindIp, BindPort);
                Event.WaitOne();
            }
            return(TcpTestServer);
        }