Brunet.Messaging.IPHandler.IPHandler C# (CSharp) Метод

IPHandler() публичный Метод

Creates a new IPHandler object by initializing the multicast and unicast socket.
The multicast socket is optional as nodes can discover other working nodes using only the unicast socket. The steps for setup for a multicast socket are bind to 0.0.0.0:port, add membership to all IP Addresses on the node, allow MulticastLoopback. The steps for the unicast socket are to create socket andbind to 0.0.0.0 and random port. Afterwhich the _listen_thread is started in the background.
public IPHandler ( ) : System
Результат System
    public IPHandler() {
      try {
        _mc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
                        ProtocolType.Udp);
        // Allows for multiple Multicast clients on the same host!
        _mc.SetSocketOption(SocketOptionLevel.Socket, 
                            SocketOptionName.ReuseAddress, true);
        _mc.Bind(new IPEndPoint(IPAddress.Any, mc_port));

        // We need to add a group membership for all IPAddresses on the local machine
        foreach(IPAddress ip in GetLocalIPAddresses()) {
          /* the LAN address tends to throw exceptions in Vista 64, while
          loopback doesn't... doing this, we make sure to at least get loopback
          discovery. */
          try{
            _mc.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
              new MulticastOption(mc_addr, ip));
          }
          catch {}
        }
        _mc.MulticastLoopback = true;
      }
      catch {
        _mc = null;
        ProtocolLog.WriteIf(ProtocolLog.Exceptions, "Unable to start listening on the" +
            "multicast port, but we can still send and request services.");
      }

      _uc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
                       ProtocolType.Udp);
      // It won't send to other mono applications on the same host otherwise...
      _uc.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback, true);
      _uc.Bind(new IPEndPoint(IPAddress.Any, 0));
      Interlocked.Exchange(ref _running, 1);
      _listen_thread = new Thread(Listen);
      _listen_thread.IsBackground = true;
      _listen_thread.Start();
    }