Exemple #1
0
 public bool SetEndPoint(IPEndPoint address)
 {
     if (address.Equals(Peer.Address))
     {
         return(false);
     }
     Peer.Address      = address;
     Peer.Addresses[0] = address;
     return(true);
 }
Exemple #2
0
        public void SendToAllExclude(Message message, IPEndPoint excluded)
        {
            byte[] buffer = SerializeMessage(message);

            foreach (var ipQueuedMessages in _endPointsQueues.Where(ip => !excluded.Equals(ip.Key)))
            {
                _udpClient.Send(buffer, buffer.Length, ipQueuedMessages.Key);
                ipQueuedMessages.Value.Add(message.GuidProperty, buffer);
            }
        }
        public void TestGetEndpointDoubleForm2()
        {
            string       daemonAddress       = "udp:127.0.0.2:2001 tcp:127.0.0.1:2000";
            IPEndPoint   expectedUDPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 2001);
            IPEndPoint   expectedTCPEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2000);
            DaemonConfig daemonConfig        = DaemonConfig.GetEndPoint(daemonAddress);

            Assert.IsTrue(expectedUDPEndpoint.Equals(daemonConfig.UDPEndpoint));
            Assert.IsTrue(expectedTCPEndpoint.Equals(daemonConfig.TCPEndpoint));
        }
Exemple #4
0
        internal void UpdateEndPoint(IPEndPoint endPoint)
        {
            if (endPoint.Equals(endPoint))
            {
                return;
            }

            this.endPoint      = endPoint;
            haveTriedConnectTo = false;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            Simulator sim = obj as Simulator;

            if (sim == null)
            {
                return(false);
            }
            return(ipEndPoint.Equals(sim.ipEndPoint));
        }
Exemple #6
0
        /// <summary>
        /// Processes received RTP packets.
        /// </summary>
        /// <param name="buffer">The raw data received on the RTP socket.</param>
        /// <param name="offset">Offset in the buffer that the received data starts from.</param>
        /// <param name="count">The number of bytes received.</param>
        /// <param name="remoteEndPoint">The remote end point the receive was from.</param>
        /// <returns>An RTP packet.</returns>
        public RTPPacket RtpReceive(byte[] buffer, int offset, int count, IPEndPoint remoteEndPoint)
        {
            if (_lastReceiveFromEndPoint == null || !_lastReceiveFromEndPoint.Equals(remoteEndPoint))
            {
                OnReceiveFromEndPointChanged?.Invoke(_lastReceiveFromEndPoint, remoteEndPoint);
                _lastReceiveFromEndPoint = remoteEndPoint;
            }

            return(new RTPPacket(buffer.Skip(offset).Take(count).ToArray()));
        }
Exemple #7
0
            public bool Equals(Server other)
            {
                if (null == other)
                {
                    return(false);
                }

                return(0 == string.Compare(identifier, other.identifier) &&
                       endpoint.Equals(other.endpoint));
            }
Exemple #8
0
        public override bool Equals(object obj)
        {
            var other = obj as TCPStateKey;

            if (other == null)
            {
                return(false);
            }
            return(Source.Equals(other.Source) && Destination.Equals(other.Destination));
        }
Exemple #9
0
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(SessionKey))
            {
                return(false);
            }
            SessionKey key = (SessionKey)obj;

            return(RemoteEndPoint.Equals(key.RemoteEndPoint) && IncomingSessionId == key.IncomingSessionId);
        }
Exemple #10
0
 public bool Is(IPEndPoint endPoint)
 {
     return(endPoint != null &&
            (InternalHttp.Equals(endPoint) ||
             ExternalHttp.Equals(endPoint) ||
             (InternalTcp != null && InternalTcp.Equals(endPoint)) ||
             (InternalSecureTcp != null && InternalSecureTcp.Equals(endPoint)) ||
             (ExternalTcp != null && ExternalTcp.Equals(endPoint)) ||
             (ExternalSecureTcp != null && ExternalSecureTcp.Equals(endPoint))));
 }
        public bool isConnectedToEndPoint(string ip, int port)
        {
            if (clientEndPoint == null)
            {
                return(false);
            }
            IPEndPoint tempEndPoint = new IPEndPoint(IPAddress.Parse(ip), port);

            return(clientEndPoint.Equals(tempEndPoint));
        }
Exemple #12
0
 private void BroadcastUDP(IPEndPoint source, byte[] bytes)
 {
     for (int i = 0; i < udp_clients.Count; i++)
     {
         if (source.Equals(udp_clients[i]) == false)
         {
             // Only broadcast to clients that didn't send the original UDP packet
             udp_server.Send(bytes, bytes.Length, udp_clients[i]);
         }
     }
 }
        public void TestIPEndPointEquality()
        {
            IPEndPoint endpoint1 = CreateEndPoint("192.10.10.99", 6001);
            IPEndPoint endpoint2 = CreateEndPoint("192.10.10.99", 6001);

            Assert.AreNotSame(endpoint1, endpoint2);
            Assert.IsFalse(object.ReferenceEquals(endpoint1, endpoint2));

            Assert.IsTrue(endpoint1.Equals(endpoint2));
            Assert.AreEqual(endpoint1, endpoint2);
        }
Exemple #14
0
 public void HandleAfterRouting(IPEndPoint address, int socketPort, byte[] payload)
 {
     if (address.Equals(ServerAddress))
     {
         if (payload[0] == 0x1c)
         {
             Router.RemoveRoute(address, socketPort, out (IPEndPoint, int)_);
             Router.RemoveRoute(Clients.First(d => d.Value == socketPort).Key, socketPort, out (IPEndPoint, int)_);
         }
     }
 }
Exemple #15
0
            public override bool Equals(object obj)
            {
                WhoSender whoObj = obj as WhoSender;

                if (whoObj != null)
                {
                    return(sender.Equals(whoObj.sender));
                }

                return(base.Equals(obj));
            }
Exemple #16
0
        public static void Equals_Compare_Success()
        {
            IPEndPoint ep  = new IPEndPoint(testIpV41, 500);
            IPEndPoint ep1 = new IPEndPoint(testIpV41, 500);
            IPEndPoint ep2 = new IPEndPoint(testIpV41, 700);
            IPEndPoint ep3 = new IPEndPoint(IPAddress.Parse("192.168.0.9"), 700);

            Assert.False(ep.Equals(null));

            Assert.True(ep.Equals(ep1));
            Assert.True(ep.GetHashCode().Equals(ep1.GetHashCode()));

            Assert.True(ep1.Equals(ep));

            Assert.False(ep.Equals(ep2));
            Assert.False(ep.GetHashCode().Equals(ep2.GetHashCode()));

            Assert.False(ep2.Equals(ep3));
            Assert.False(ep2.GetHashCode().Equals(ep3.GetHashCode()));
        }
Exemple #17
0
 public static String GetName(IPEndPoint iep, List <Client> list)
 {
     foreach (Client c in list)
     {
         if (IPEndPoint.Equals(c.iep, iep))
         {
             return(c.name);
         }
     }
     return(null);
 }
Exemple #18
0
 private bool ValidateConnexionState()
 {
     if (NeedConnexion())
     {
         return(IsConnected() && (sender.Equals(clientInformations.client.serverEndPoint)));
     }
     else
     {
         return(!IsConnected());
     }
 }
Exemple #19
0
        public void Ctor_LongInt()
        {
            IPEndPoint ep = new IPEndPoint(0, 80);

            Assert.AreEqual(new IPAddress(0), ep.Address, "Address");
            Assert.AreEqual(AddressFamily.InterNetwork, ep.AddressFamily, "AddressFamily");
            Assert.AreEqual(80, ep.Port, "Port");

            Assert.Throws <ArgumentNullException> (delegate {
                ep.Create(null);
            }, "Create(null)");

            // note: documented as ArgumentException
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                SocketAddress sa = new SocketAddress(AddressFamily.InterNetwork, 1);
                Assert.IsTrue(sa.Size < 8, "Size");
                ep.Create(sa);
            }, "Create(bad-size)");

            Assert.Throws <ArgumentException> (delegate {
                SocketAddress sa = new SocketAddress(AddressFamily.InterNetworkV6);
                Assert.IsTrue(sa.Size >= 8, "SizeV6");
                ep.Create(sa);
            }, "Create(InterNetworkV6)");
            Assert.Throws <ArgumentException> (delegate {
                SocketAddress sa = new SocketAddress(AddressFamily.Unknown);
                ep.Create(sa);
            }, "Create(Unknown)");
            Assert.Throws <ArgumentException> (delegate {
                SocketAddress sa = new SocketAddress(AddressFamily.Unspecified);
                ep.Create(sa);
            }, "Create(Unspecified)");
            EndPoint ep2 = ep.Create(new SocketAddress(AddressFamily.InterNetwork));

            Assert.IsFalse(ep.Equals(null), "Equals(null)");
            Assert.IsTrue(ep.Equals(ep), "Equals(self)");
            Assert.IsFalse(ep.Equals(ep2), "Equals(Create)");

            Assert.AreEqual("InterNetwork:16:{0,80,0,0,0,0,0,0,0,0,0,0,0,0}", ep.Serialize().ToString(), "Serialize");
            Assert.AreEqual("0.0.0.0:80", ep.ToString(), "ToString");
        }
Exemple #20
0
 public override bool Equals(object rval)
 {
     if (rval is IPv4Uri)
     {
         var r = (IPv4Uri)rval;
         return(_endpoint.Equals(r._endpoint));
     }
     else
     {
         return(false);
     }
 }
        public override bool Equals(object obj)
        {
            bool ret = false;

            if (obj != null)
            {
                NodeAddress tmp = obj as NodeAddress;
                ret = IPEndPoint.Equals(tmp.IPEndPoint);
            }

            return(ret);
        }
 private void HandleDisconnect(string msg, IPEndPoint source)
 {
     if (source.Equals(masterEP))
     {
         Logger.Info("Slave disconnected. Master at " + masterEP + " signalled disconnect.");
         connected = false;
         if (OnDisconnected != null)
         {
             OnDisconnected(this, null);
         }
     }
 }
Exemple #23
0
        internal static bool FastEquals(this IPEndPoint ip1, IPEndPoint ip2)
        {
#if NETFX_CORE || WINDOWS_UWP
            return(ip1.Equals(ip2));
#else
#pragma warning disable 0618
            return(ip1.Address.Address.Equals(ip2.Address.Address) && ip1.Port == ip2.Port);

#pragma warning restore 0618
#endif
            // TODO if IPv6
        }
Exemple #24
0
 //TODO return error code
 public void Recieve(byte[] buffer, out IPEndPoint endPoint)
 {
     _transport.Recieve(buffer, out endPoint);
     if (endPoint.Equals(_host))
     {
         return;
     }
     for (var i = 0; i < buffer.Length; i++) //Dump payload
     {
         buffer[i] = 0;
     }
 }
        static void Main(string[] args)
        {
            UdpClient server = new UdpClient(9050);

            //b2: Trao doi du lieu
            List <int>        dssoluong = new List <int>();
            List <int>        dsso      = new List <int>();
            List <int>        dsn       = new List <int>();
            List <IPEndPoint> dsclient  = new List <IPEndPoint>();
            IPEndPoint        client    = new IPEndPoint(IPAddress.Any, 0);

            byte[] data1 = new byte[10];
            while (true)
            {
                data1 = server.Receive(ref client);
                string so1 = Encoding.ASCII.GetString(data1, 0, data1.Length);
                int    a   = int.Parse(so1);
                int    i;
                int    b, kq;
                for (i = 0; i < dsclient.Count; i++)
                {
                    if (client.Equals(dsclient.ElementAt(i)))
                    {
                        if (dssoluong.ElementAt(i) < dsn.ElementAt(i))
                        {
                            dssoluong[i]++;
                            b       = dsso.ElementAt(i);
                            kq      = a + b;
                            dsso[i] = kq;
                            break;
                        }
                        if (dssoluong.ElementAt(i) == dsn.ElementAt(i))
                        {
                            b       = dsso.ElementAt(i);
                            kq      = a + b;
                            dsso[i] = kq;
                            byte[] data3 = new byte[10];
                            data3 = BitConverter.GetBytes(kq);
                            server.Send(data3, data3.Length, client);
                            break;
                        }
                    }
                }
                if (i == dsclient.Count)
                {
                    dsclient.Add(client);
                    dsso.Add(0);
                    dsn.Add(a);
                    dssoluong.Add(1);
                }
            }
        }
Exemple #26
0
        public IEnumerable <IPEndPoint> GetServers(Region region, string?filter = null)
        {
            using (var client = new UdpClient())
            {
                int serverCount;
                var anyEndpoint  = new IPEndPoint(IPAddress.Any, 0);
                var lastEndpoint = anyEndpoint;

                do
                {
                    serverCount = 0;
                    var query = new List <byte> {
                        0x31, (byte)region
                    };
                    query.AddRange(Encoding.ASCII.GetBytes(lastEndpoint.ToString()));
                    query.Add(0); // ip termination

                    if (!String.IsNullOrWhiteSpace(filter))
                    {
                        query.AddRange(Encoding.ASCII.GetBytes(filter));
                    }
                    query.Add(0); // filter termination

                    client.Send(query.ToArray(), query.Count, _endpoint);
                    var serverData = client.Receive(ref AnyIpEndPoint);

                    using (var br = new BinaryReader(new MemoryStream(serverData)))
                    {
                        if (br.ReadInt32() != -1 || br.ReadInt16() != 0x0A66)
                        {
                            yield break;
                        }

                        while (br.BaseStream.Position < br.BaseStream.Length)
                        {
                            var ipBytes = br.ReadBytes(4);
                            var port    = (ushort)IPAddress.NetworkToHostOrder(br.ReadInt16());

                            var server = new IPEndPoint(new IPAddress(ipBytes), port);
                            if (server.Equals(anyEndpoint))
                            {
                                yield break;
                            }
                            yield return(server);

                            lastEndpoint = server;
                            serverCount++;
                        }
                    }
                } while (serverCount > 0);
            }
        }
Exemple #27
0
        static void OnUdpData(IAsyncResult result)
        {
            UdpClient  socket = result.AsyncState as UdpClient;
            IPEndPoint source = new IPEndPoint(IPAddress.Any, 51600);

            try
            {
                byte[] message = socket.EndReceive(result, ref source);
                bool   conn    = false;
                foreach (var item in list)
                {
                    if (source.Equals(item.ip))
                    {
                        conn = true;
                    }
                }

                string      rec_name    = Encoding.Default.GetString(message, 0, 8).TrimEnd();
                UDPCommands rec_command = (UDPCommands)BitConverter.ToInt32(message, 8);

                Console.WriteLine("Received data from...");
                Console.WriteLine("Name=" + rec_name);
                Console.WriteLine("Command=" + rec_command.ToString());

                if (!conn)
                {
                    var a = new User("test", source);
                    list.AddLast(a);
                    Console.WriteLine("Adding connection to list...");
                }

                if (rec_command == UDPCommands.MESSAGE)
                {
                    byte[] rec_message = new byte[rec_name.Length + 2 + message.Length - 12];
                    byte[] padd        = Encoding.Default.GetBytes(": ");
                    Buffer.BlockCopy(message, 0, rec_message, 0, rec_name.Length);
                    Buffer.BlockCopy(padd, 0, rec_message, rec_name.Length, 2);
                    Buffer.BlockCopy(message, 12, rec_message, rec_name.Length + 2, message.Length - 12);
                    Console.WriteLine(Encoding.Default.GetString(rec_message) + " (from " + source.Address + ":" + source.Port + ")");

                    foreach (var item in list)
                    {
                        socket.Send(rec_message, rec_message.Length, item.ip);
                    }
                }
            }
            catch
            {
            }

            socket.BeginReceive(new AsyncCallback(OnUdpData), socket);
        }
Exemple #28
0
        public static void ManageControllers(ref List <Controller> l)
        {
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            s.Bind(new IPEndPoint(IPAddress.Any, 1235));
            while (true)
            {
                EndPoint ep     = new IPEndPoint(IPAddress.Any, 1235);
                byte[]   buffer = new byte[1000];
                if (l.Count == 0)
                {
                    s.ReceiveFrom(buffer, ref ep);
                    string get = ASCIIEncoding.ASCII.GetString(buffer);

                    l.Add(new Controller(get, (IPEndPoint)ep));
                }
                else
                {
                    for (int i = 0; i < l.Count; i++)
                    {
                        Controller c = l[i];

                        try
                        {
                            try
                            {
                                s.SendTo(ASCIIEncoding.ASCII.GetBytes(c.GetString()), c.GetAddr());



                                s.ReceiveFrom(buffer, ref ep);
                            }
                            catch
                            {
                                l.RemoveAt(i);
                                throw new Exception();
                            }
                            while (!ep.Equals(c.GetAddr()))
                            {
                                l.Add(new Controller(ASCIIEncoding.ASCII.GetString(buffer), (IPEndPoint)ep));
                                s.ReceiveFrom(buffer, ref ep);
                            }
                            c.setFromString(ASCIIEncoding.ASCII.GetString(buffer));
                        }
                        catch
                        {
                        }
                    }
                }
                Thread.Sleep(10);
            }
        }
 private void InitializeNetwork()
 {
     if (Utility.IsMulticast(groupEP) && (!nextHopEP.Equals(groupEP)))
     {
         // reflector based session
         rtpNetworkListener = new UdpListener(groupEP, nextHopEP, RtpSession.DefaultNetworkTimeout);
     }
     else
     {
         // multicast or direct unicast: no reflector needed
         rtpNetworkListener = new UdpListener(nextHopEP, RtpSession.DefaultNetworkTimeout);
     }
 }
        /// <summary>
        /// Returns if the passed <paramref name="otherEndpoint"/> matches the specified server binding interface.
        /// </summary>
        /// <param name="otherEndpoint">The endpoint to match to <see cref="Endpoint"/>.</param>
        /// <remarks>If the binding endpoint is any IP (0.0.0.0 IPV4 or [::] IPV6 address) just checks the port.</remarks>
        /// <returns></returns>
        public bool Matches(IPEndPoint otherEndpoint)
        {
            IPEndPoint endpoint = IPEndPoint.Parse(this.Endpoint);

            if (endpoint.Address.IsAnyIP())
            {
                return(endpoint.Port == otherEndpoint.Port);
            }
            else
            {
                return(otherEndpoint.Equals(this.Endpoint));
            }
        }
 public void Send(byte[] dgram, int bytes, IPEndPoint endPoint)
 {
     //lock (locker)
     //{
         if (isConnected)
         {
             if (!endPoint.Equals(udpClient.Client.RemoteEndPoint))
                 throw new CommunicationException("Attempted to send UDP packet to an endPoint other than that to which this UDP client is specifically connected.");
             else
                 udpClient.Send(dgram, bytes);
         }
         else
             udpClient.Send(dgram, bytes, endPoint);
     //}
 }
Exemple #32
0
        public static void Equals_Compare_Success()
        {
            IPEndPoint ep = new IPEndPoint(testIpV41, 500);
            IPEndPoint ep1 = new IPEndPoint(testIpV41, 500);
            IPEndPoint ep2 = new IPEndPoint(testIpV41, 700);
            IPEndPoint ep3 = new IPEndPoint(IPAddress.Parse("192.168.0.9"), 700);

            Assert.False(ep.Equals(null));

            Assert.True(ep.Equals(ep1));
            Assert.True(ep.GetHashCode().Equals(ep1.GetHashCode()));

            Assert.True(ep1.Equals(ep));

            Assert.False(ep.Equals(ep2));
            Assert.False(ep.GetHashCode().Equals(ep2.GetHashCode()));

            Assert.False(ep2.Equals(ep3));
            Assert.False(ep2.GetHashCode().Equals(ep3.GetHashCode()));
        }