コード例 #1
0
    public TCPServer(TCPTransfer ui)
    {
        _ui = ui ?? throw new ArgumentNullException(nameof(ui));

        // Establish the local endpoint for the socket.
        // The DNS name of the computer
        // running the listener is "host.contoso.com".
        _ui.WriteLine($"StartListening() - host name: {Dns.GetHostName()}");

        IPHostEntry ipHostInfo    = Dns.GetHostEntry(Dns.GetHostName());
        IPAddress   ipAddress     = ipHostInfo.AddressList[0];
        IPEndPoint  localEndPoint = new IPEndPoint(ipAddress, TCPTransfer.PORT);

        // Create a TCP/IP socket.
        _socket = new Socket(ipAddress.AddressFamily,
                             SocketType.Stream, ProtocolType.Tcp);

        // Bind the socket to the local endpoint and listen for incoming connections.

        _socket.Bind(localEndPoint);
        _socket.Listen(100);
    }
コード例 #2
0
 public TCPClient(TCPTransfer ui)
 {
     _ui = ui ?? throw new ArgumentNullException(nameof(ui));
 }