Exemplo n.º 1
0
 public UdpEvent(UdpReceiver _receiver, byte[] _datas, IPEndPoint _remoteIEP, uint _conv, UdpEventType _evtType, bool _serverflag)
 {
     receiver   = _receiver;
     conv       = _conv;
     remoteIEP  = _remoteIEP;
     evtType    = _evtType;
     datas      = _datas;
     serverflag = _serverflag;
 }
Exemplo n.º 2
0
        public override void Update()
        {
            UdpEvent ev;

            while (socket.Poll(out ev))
            {
                UdpEventType eventType = ev.EventType;
                if (eventType <= UdpEventType.PacketReceived)
                {
                    switch (eventType)
                    {
                    case UdpEventType.ConnectFailed:
                    case UdpEventType.ConnectRefused:
                    case UdpEventType.Connected:
                        ProcessConnect(ev);
                        break;

                    case (UdpEventType)5:
                    case (UdpEventType)7:
                    case (UdpEventType)9:
                        break;

                    case UdpEventType.Disconnected:
                        ProcessDisconnect(ev);
                        break;

                    default:
                        if (eventType == UdpEventType.PacketReceived)
                        {
                            goto IL_5C;
                        }
                        break;
                    }
                }
                else
                {
                    if (eventType != UdpEventType.ServerForceQuit)
                    {
                        if (eventType == UdpEventType.StreamDataReceived)
                        {
                            goto IL_5C;
                        }
                    }
                    else
                    {
                        ProcessServerForceQuit(ev);
                    }
                }
                continue;
IL_5C:
                ProcessReceive(ev);
            }
        }
Exemplo n.º 3
0
        public override bool ConnectSync(IPEndPoint localAddress, IPEndPoint remoteAddress, int timeout)
        {
            long num = DateTime.Now.ToFileTime() / 10000L;
            bool result;

            if (IsConnected())
            {
                UdpIPv4Address udpIPv4Address = new UdpIPv4Address(NetUtil.GetLongAddress(remoteAddress.Address.GetAddressBytes()));
                UdpIPv4Address address        = this.udpRemote.Address;
                if (address.Equals(udpIPv4Address) && (int)udpRemote.Port == remoteAddress.Port)
                {
                    result = true;
                    return(result);
                }
                LoggerManager.Instance.Warn("ConnectSync found already connected new addr {0} old addr {1}", remoteAddress.ToString(), udpRemote.ToString());
            }

            if (!IsConnecting())
            {
                udpRemote = new UdpEndPoint(new UdpIPv4Address(NetUtil.GetLongAddress(remoteAddress.Address.GetAddressBytes())), (ushort)remoteAddress.Port);
                remote    = remoteAddress;
                socket.Connect(udpRemote);
            }

            object obj = statusLock;

            Monitor.Enter(obj);
            try
            {
                connectionStatus = ConnectionStatus.Connecting;
            }
            finally
            {
                Monitor.Exit(obj);
            }

            long num2 = DateTime.Now.ToFileTime() / 10000L;

            while (num2 - num < (long)(timeout * 1000))
            {
                UdpEvent ev;
                if (socket.Poll(out ev))
                {
                    UdpEventType eventType = ev.EventType;
                    switch (eventType)
                    {
                    case UdpEventType.ConnectFailed:
                    case UdpEventType.ConnectRefused:
                    case UdpEventType.Connected:
                        ProcessConnect(ev);
                        result = (ev.EventType == UdpEventType.Connected);
                        return(result);

                    case (UdpEventType)5:
                    case (UdpEventType)7:
                        break;

                    default:
                        if (eventType == UdpEventType.ServerForceQuit)
                        {
                            ProcessServerForceQuit(ev);
                            result = false;
                            return(result);
                        }
                        break;
                    }
                }
                Thread.Sleep(10);
                num2 = DateTime.Now.ToFileTime() / 10000L;
            }

            Monitor.Enter(obj = this.statusLock);
            try
            {
                connectionStatus = ConnectionStatus.Disconnected;
            }
            finally
            {
                Monitor.Exit(obj);
            }
            result = false;
            return(result);
        }