Exemple #1
0
        private void BuildSocket(IPAddress bindingAddress)
        {
            lock (this)
            {
                if (this.sock == null)
                {
                    if (this.buf == null)
                    {
                        this.buf = new byte[65536];                                       //max udp frame size
                    }
                    this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);


                    //IPAddress wireless = (NetworkAddress.GetBindingAddressByType(NetworkAddress.BindingType.Wireless));
                    //if (bindingAddress.Equals(wireless) && (wireless.Equals(IPAddress.Any) == false) && MultiplexerUtil.USE_MULTIPLEXER)
                    if (NetworkAddress.IsRobotWirelessIP(bindingAddress) && MultiplexerUtil.USE_MULTIPLEXER)
                    {
                        Console.WriteLine("USING MULTIPLEXER for " + ip);
                        this.sock.Bind(new IPEndPoint(bindingAddress, this.port));
                        this.sock.BeginReceive(this.buf, 0, this.buf.Length, SocketFlags.None, ReceiveCallback, null);
                    }
                    else
                    {
                        this.sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
                        this.sock.Bind(new IPEndPoint(bindingAddress, this.port));
                        this.sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(this.ip, bindingAddress));
                        this.sock.BeginReceive(this.buf, 0, this.buf.Length, SocketFlags.None, ReceiveCallback, null);
                    }
                }
            }
        }
Exemple #2
0
        private void BuildSocket(IPAddress bindingAddress)
        {
            lock (this)
            {
                if (this.sock == null)
                {
                    this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                    this.sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

                    //IPAddress wireless = (NetworkAddress.GetBindingAddressByType(NetworkAddress.BindingType.Wireless));
                    //if (bindingAddress.Equals(wireless) && (wireless.Equals(IPAddress.Any) == false) && MultiplexerUtil.USE_MULTIPLEXER)
                    if (NetworkAddress.IsRobotWirelessIP(bindingAddress) && MultiplexerUtil.USE_MULTIPLEXER)
                    {
                        Console.WriteLine("Using Multiplexer for IP : " + ip);
                        //Why is this here?
                        //this.sock.Bind(new IPEndPoint(bindingAddress, this.port));
                        multiplexMode = true;
                    }
                    else
                    {
                        this.sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10);
                        this.sock.Bind(new IPEndPoint(bindingAddress, this.port));
                        this.sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(this.ip, bindingAddress));
                        multiplexMode = false;
                        //multiplexMode = true;
                    }
                }
            }
        }