コード例 #1
0
ファイル: DelegateExample.cs プロジェクト: pedoc/Network
 public void Demo()
 {
     //1. Establish a connection to the server.
     container = ConnectionFactory.CreateClientConnectionContainer("127.0.0.1", 1234);
     //2. Register what happens if we get a connection
     container.ConnectionEstablished += connectionEstablished;
 }
コード例 #2
0
        public PlayerClient(string ip, int port)
        {
            clientConnectionContainer = ConnectionFactory.CreateClientConnectionContainer(ip, port);
            clientConnectionContainer.ConnectionEstablished += ConnectionEstablished;
            clientConnectionContainer.ConnectionLost        += ConnectionLost;

            _player = new PlayerWrapper(false);

            while (!clientConnectionContainer.IsAlive)
            {
            }
        }
コード例 #3
0
        public void Demo()
        {
            //1. Establish a connection to the server.
            ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer("127.0.0.1", 1234);

            //2. Register what happens if we get a connection
            container.ConnectionEstablished += (connection, type) =>
            {
                Console.WriteLine($"{type.ToString()} Connection established");
                //3. Register what happens if we receive a packet of type "CalculationResponse"
                connection.RegisterPacketHandler <CalculationResponse>((response, con) => Console.WriteLine($"Answer received {response.Result}"), this);
                //4. Send a calculation request.
                connection.Send(new CalculationRequest(10, 10), this);
            };
        }
コード例 #4
0
#pragma warning disable CS1998 // Bei der asynchronen Methode fehlen "await"-Operatoren. Die Methode wird synchron ausgeführt.
        public async void Demo()
#pragma warning restore CS1998 // Bei der asynchronen Methode fehlen "await"-Operatoren. Die Methode wird synchron ausgeführt.
        {
            //1. Establish a connection.
            ClientConnectionContainer container = ConnectionFactory.CreateSecureClientConnectionContainer("127.0.0.1", 1234);

            //2. Register what happens if we get a connection
            container.ConnectionEstablished += (connection, type) =>
            {
                Console.WriteLine($"{type.ToString()} Connection established");
                //3. Register what happens if we receive a packet of type "CalculationResponse"
                connection.RegisterPacketHandler <CalculationResponse>((response, con) => Console.WriteLine($"Answer received {response.Result}"), this);
                //4. Send a calculation request.
                connection.Send(new CalculationRequest(10, 10), this);
            };
        }
コード例 #5
0
ファイル: IPv6Example.cs プロジェクト: zockware/Network
#pragma warning disable CS1998 // Bei der asynchronen Methode fehlen "await"-Operatoren. Die Methode wird synchron ausgeführt.

        public async void Demo()
#pragma warning restore CS1998 // Bei der asynchronen Methode fehlen "await"-Operatoren. Die Methode wird synchron ausgeführt.
        {
            //1. Establish a connection to the server.
            ClientConnectionContainer container = ConnectionFactory.CreateClientConnectionContainer("::1", 1234);

            //2. Register what happens if we get a connection
            container.ConnectionEstablished += async(connection, type) =>
            {
                connection.EnableLogging = true;
                Console.WriteLine($"{type.ToString()} Connection established");
                //3. Send a request packet async and directly receive an answer.
                CalculationResponse response = await connection.SendAsync <CalculationResponse>(new CalculationRequest(10, 10));

                Console.WriteLine($"Answer received {response.Result}");
            };
        }
コード例 #6
0
        private void btnVerbinden_Click(object sender, EventArgs e)
        {
            if (oClientConnectionContainer == null)
            {
                // Client Connection erstellen, wenn noch nicht vorhanden
                oClientConnectionContainer = ConnectionFactory.CreateClientConnectionContainer(txtServer.Text, Convert.ToInt32(txtPort.Text));
                oClientConnectionContainer.AutoReconnect = true;

                oClientConnectionContainer.ConnectionEstablished += ClientConnectionContainer_ConnectionEstablished;
                oClientConnectionContainer.ConnectionLost        += oClientConnectionContainer_ConnectionLost;

                txtPort.Enabled = false;   // Eine Änderung des Ports ist während der Runtime nicht möglich
            }

            oClientConnectionContainer.Reconnect();
            btnVerbinden.Enabled = false;
            btnTrennen.Enabled   = true;
        }
コード例 #7
0
 public Client(string ip, int port)
 {
     clientConnectionContainer = ConnectionFactory.CreateClientConnectionContainer(ip, port);
     clientConnectionContainer.ConnectionEstablished += connectionEstablished;
 }