Exemplo n.º 1
0
        private UDPPort Start(string iP, int port)
        {
            UDPPort udpPort = new UDPPort(iP, port);

            try
            {
                IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(iP), 0);
                this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                this.socket.ReceiveBufferSize = 1024;
                this.socket.SendBufferSize    = 1024;
                while (true)
                {
                    ipEndPoint.Port = port;
                    try
                    {
                        this.socket.Bind((EndPoint)ipEndPoint);
                        udpPort.Port = ipEndPoint.Port;
                        break;
                    }
                    catch
                    {
                    }
                    ++port;
                }
                this.runningFlag = true;
                this.remotePoint = (EndPoint) new IPEndPoint(IPAddress.Parse(udpPort.IP), udpPort.Port);
                this.witeThread  = new Thread(new ThreadStart(this.Listen));
                this.witeThread.Start();
            }
            catch
            {
            }
            return(udpPort);
        }
Exemplo n.º 2
0
 public UDPSocket(string iP, int port)
 {
     this.Port = this.Start(iP, port);
 }