Exemple #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);
        }
Exemple #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);
            }
        }