示例#1
0
        public EmmiterTcpClient Connect(int port, string address = DefaultConnectAddress, Action onConnect = null)
        {
            var client = new TcpClient();

            var socket = new EmmiterTcpClient(client);

            client.ConnectAsync(new IPAddress(address.GetIpAddressBytes()), port).ContinueWith(t =>
            {
                if (onConnect != null)
                {
                    onConnect();
                }

                socket.Run();
            });

            return(socket);
        }
示例#2
0
        public async Task Listen(int port, string address)
        {
            var bytes = address.Split('.').Select(byte.Parse).ToArray();

            var localEndpoint = new IPEndPoint(new IPAddress(bytes), port);

            this.serverSocket = new TcpListener(localEndpoint);

            this.serverSocket.Start();

            while (!this.closed)
            {
                var clientSocket = await this.serverSocket.AcceptTcpClientAsync();

                var emmiterSocket = new EmmiterTcpClient(clientSocket);

                emmiterSocket.Run();

                this.onConnection(emmiterSocket);
            }
        }