Exemplo n.º 1
0
        public static IPAddress GetLocalIP(ServerBindType bindType)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());

            foreach (IPAddress address in hostEntry.AddressList)
            {
                if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    switch (bindType)
                    {
                    case ServerBindType.Any:
                        return(address);

                    case ServerBindType.Public:
                    case ServerBindType.PublicPrivate:
                        if (TcpServerBase <TClient> .IsPrivateIP(address))
                        {
                            break;
                        }
                        return(address);

                    case ServerBindType.Private:
                    case ServerBindType.PrivatePublic:
                        if (!TcpServerBase <TClient> .IsPrivateIP(address))
                        {
                            break;
                        }
                        return(address);
                    }
                }
            }
            foreach (IPAddress address3 in hostEntry.AddressList)
            {
                if (address3.AddressFamily == AddressFamily.InterNetwork)
                {
                    switch (bindType)
                    {
                    case ServerBindType.PublicPrivate:
                        if (!TcpServerBase <TClient> .IsPrivateIP(address3))
                        {
                            break;
                        }
                        return(address3);

                    case ServerBindType.PrivatePublic:
                        if (TcpServerBase <TClient> .IsPrivateIP(address3))
                        {
                            break;
                        }
                        return(address3);
                    }
                }
            }
            throw new SocketException(10049);
        }
Exemplo n.º 2
0
 public void Start(JobProcessor jobProcessor, ServerBindType bindType, int port)
 {
     this.Start(jobProcessor, TcpServerBase <TClient> .GetLocalIP(bindType), port);
 }