Пример #1
0
            public void Logout()
            {
                for (var it = _Clients.Begin(); it;)
                {
                    var itCheck = it;
                    it.MoveNext();

                    _Logout(itCheck);
                }
            }
Пример #2
0
            public void SendAll(SProto Proto_)
            {
                for (var it = _Servers.Begin(); it != _Servers.End(); it.MoveNext())
                {
                    if (!it.Data.Logon)
                    {
                        continue;
                    }

                    _NetS.Send((TPeerCnt)it.Index, new SHeader(EProto.CsUserProto), Proto_);
                }
            }
Пример #3
0
 public new void CloseAll()
 {
     for (var it = _PeersAndConnectings.Begin(); it != _PeersAndConnectings.End(); it = _PeersAndConnectings.Begin())
     {
         var Peer = _Peers.Get(it.Index);
         if (Peer)
         {
             base.Close(it.Data);
         }
         else
         {
             var PeerNum = it.Data.PeerNum;
             _PeersAndConnectings.Remove(it);
             _Connectings.Remove((Int32)PeerNum);
             _LinkFail(PeerNum, ENetRet.UserClose);
         }
     }
 }
Пример #4
0
            public void Proc()
            {
                var NowTick = Environment.TickCount;

                for (var it = _Connects.Begin(); it;)
                {
                    var itCheck = it;
                    it.MoveNext();

                    if ((NowTick - itCheck.Data.ConnectTick) < _TimeOutTicks)
                    {
                        break;
                    }

                    itCheck.Data.Socket.Close();

                    _Connects.Remove(itCheck);
                }
            }
Пример #5
0
            public new void Proc()
            {
                base.Proc();

                for (var it = _Connectings.Begin(); it != _Connectings.End();)
                {
                    var itCheck = it;
                    it.MoveNext();

                    var itPeer   = _PeersAndConnectings.Get(itCheck.Index);
                    var PeerNum  = itPeer.Data.PeerNum;
                    var NamePort = itCheck.Data;
                    _Connectings.Remove(itCheck);

                    try
                    {
                        Socket Sock = null;

                        AddressFamily[] AddressFamilies = { AddressFamily.InterNetwork, AddressFamily.InterNetworkV6 };

                        foreach (var i in NamePort.GetIPAddresses())
                        {
                            if (i.AddressFamily != AddressFamily.InterNetwork)
                            {
                                continue;
                            }

                            foreach (var a in AddressFamilies)
                            {
                                Sock = new Socket(a, SocketType.Stream, ProtocolType.Tcp)
                                {
                                    NoDelay           = _NoDelay,
                                    SendBufferSize    = _SendBuffSize,
                                    ReceiveBufferSize = _RecvBuffSize
                                };

                                var RecvEvent = new SocketAsyncEventArgs();
                                RecvEvent.Completed     += new EventHandler <SocketAsyncEventArgs>(_Worker);
                                RecvEvent.UserToken      = new _SConnectingInfo(itPeer.Data, Sock);
                                RecvEvent.RemoteEndPoint = new IPEndPoint(i, NamePort.Port);

                                bool ConnRet = false;

                                try
                                {
                                    ConnRet = Sock.ConnectAsync(RecvEvent);
                                }
                                catch
                                {
                                    Sock = null;
                                    continue;
                                }

                                if (!ConnRet)
                                {
                                    if (!RecvEvent.ConnectSocket.Connected) // Android(iOS는 미확인)에서 Wifi, Data 모두 끈 상태에서 여기에 들어오므로 여기서 연결여부 체크
                                    {
                                        Sock = null;
                                        continue;
                                    }

                                    _Link(itPeer.Data, Sock, RecvEvent);
                                }
                                else
                                {
                                    _ConnectTimeOut.Add((Int32)PeerNum, Sock);
                                }

                                break; // Success
                            }

                            if (Sock != null)
                            {
                                break; // Success
                            }
                        }

                        if (Sock == null)
                        {
                            throw new Exception("Can not new Socket");
                        }
                    }
                    catch (ExceptionNet Exception_)
                    {
                        if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null)
                        {
                            throw Exception_.InnerException;
                        }
                        else
                        {
                            _PeersAndConnectings.Remove(itPeer);
                            _LinkFail(PeerNum, Exception_.GetRet());
                            continue;
                        }
                    }
                    catch
                    {
                        _PeersAndConnectings.Remove(itPeer);
                        _LinkFail(PeerNum, ENetRet.SocketError);
                        continue;
                    }
                }

                for (var LFConnect = _Connects.GetPopBuf();
                     LFConnect != null;
                     LFConnect = _Connects.GetPopBuf())
                {
                    var ConnectInfo = (_SConnectingInfo)LFConnect.Event.UserToken;
                    var itPeer      = _PeersAndConnectings.Get((Int32)ConnectInfo.Key.PeerNum);
                    if (itPeer && itPeer.Data.Equals(ConnectInfo.Key))
                    {
                        if (LFConnect.NetRet == ENetRet.Ok)
                        {
                            try
                            {
                                _Link(ConnectInfo.Key, ConnectInfo.socket, LFConnect.Event);
                            }
                            catch (ExceptionNet Exception_)
                            {
                                if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null)
                                {
                                    throw Exception_.InnerException;
                                }
                                else
                                {
                                    LFConnect.NetRet = Exception_.GetRet();
                                }
                            }
                            catch
                            {
                                LFConnect.NetRet = ENetRet.SystemError;
                            }
                        }

                        if (LFConnect.NetRet != ENetRet.Ok)
                        {
                            _ConnectTimeOut.Remove(itPeer.Index);
                            _PeersAndConnectings.Remove(itPeer);
                            _LinkFail(ConnectInfo.Key.PeerNum, LFConnect.NetRet);
                        }
                    }

                    _Connects.Pop();
                }

                if (_ProcPeriod.CheckAndNextLoose())
                {
                    _ConnectTimeOut.Proc();
                }
            }