Exemple #1
0
        public void RecieveProtocol()
        {
            IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

            try
            {
                while (true)
                {
#if DEBUG
                    Console.WriteLine("Waiting for protocol");
#endif
                    byte[] bytes = _Listener.Receive(ref remoteIpEndPoint);
                    string data  = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
#if DEBUG
                    Console.WriteLine($"Data received: {data}");
#endif

                    Protocol.Protocol protocol = JsonConvert.DeserializeObject <Protocol.Protocol>(data);

                    ProtocolReceived?.Invoke(new ProtocolReceivedArguments(protocol, remoteIpEndPoint.Address.ToString(), remoteIpEndPoint.Port));
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
        }
 /// <summary>
 /// Listeners the protocol recieved.
 /// </summary>
 /// <param name="protocolReceivedArguments">Protocol received arguments.</param>
 private void Listener_ProtocolRecieved(ProtocolReceivedArguments protocolReceivedArguments)
 {
     ProtocolReceived?.Invoke(protocolReceivedArguments);
 }