Ejemplo n.º 1
0
        public void StartConnect()
        {
            IPAddress ipAddress = IPAddress.Parse(IP);

            remoteEP = new IPEndPoint(ipAddress, Port);

            if (connection != null && !connection.m_Disposed)
            {
                connection.Dispose();
                connection = null;
            }

            connection = new JHSConnection();
            connection.Init(true);

            if (NetConfig.logFilter >= JHSLogFilter.Developer)
            {
                JHSDebug.Log("JHSNetworkManager Connecting to Server reconnect attmpt:" + m_RecconectTry);
            }
            connection.m_socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
            {
                Blocking = false
            };
            connection.m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 1048576);
            connection.m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, 1048576);
            connection.m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1);
            connection.m_socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 0);
            connection.m_socket.BeginConnect(remoteEP, ConnectCallback, connection.m_socket);
            Connecting        = true;
            PermaDisconnected = false;
        }
Ejemplo n.º 2
0
 internal void AddConnection(JHSConnection con)
 {
     Connected(con);
     if (NetConfig.logFilter >= JHSLogFilter.Developer)
     {
         JHSDebug.Log("JHSNetworkManager :: Added Connection To Pool.");
     }
 }
Ejemplo n.º 3
0
 internal void Connected(JHSConnection con)
 {
     InvokeHandler(new JHSNetworkMessage()
     {
         msgType = InternalMessages.CONNECTED,
         conn    = con,
         reader  = new JHSNetworkReader()
     });
 }
 internal void Discconnectx(JHSConnection con)
 {
     if (m_activeTransport != null)
     {
         m_activeTransport.Disconnect(con);
         if (NetConfig.logFilter >= JHSLogFilter.Log && con != null)
         {
             JHSDebug.Log("JHSNetworkManager :: Disconnected :" + con.connectionId);
         }
     }
 }
Ejemplo n.º 5
0
 public bool Disconnect(JHSConnection con)
 {
     JHSNetworkClient.Instance.ClientConnected = false;
     if (con != null)
     {
         JHSNetworkClient.PushMessage(new JHSNetworkMessage
         {
             msgType = RecconectTry == m_RecconectTry ? InternalMessages.DISCONNECT : InternalMessages.DISCONNECT_BUT_WILL_RECONNECT,
             conn    = con,
             reader  = new JHSNetworkReader()
         });
         JHSStatisiticsManager.Remove(con);
         con.Dispose();
         Connected        = false;
         LastTryToConnect = JHSTime.Time + NetConfig.ReconnectTimeOut;
         return(true);
     }
     LastTryToConnect = JHSTime.Time + NetConfig.ReconnectTimeOut;
     Connected        = false;
     return(false);
 }
        internal void HandleClientHandShake(JHSNetworkMessage netMsg)
        {
            HandShakeMsg packet = netMsg.ReadMessage <HandShakeMsg>();

            if (packet != null)
            {
                if (packet.OP == 0) //VER VERSION
                {
                    netMsg.conn.connectionId = packet.Version;
                    netMsg.conn.stage        = PerStage.Connecting;
                    HandShakeMsg p = new HandShakeMsg
                    {
                        Version = (uint)NetConfig.Key,
                        OP      = 1
                    };
                    netMsg.conn.Send(InternalMessages.HeandShake_Server, p);
                }
                else if (packet.OP == 1)
                {
                    if (packet.Version == NetConfig.Key)
                    {
                        netMsg.conn.stage = PerStage.Connected;
                        HandShakeMsg p = new HandShakeMsg
                        {
                            Version = (uint)NetConfig.Key,
                            OP      = 2
                        };
                        netMsg.conn.Send(InternalMessages.HeandShake_Server, p);
                        ClientConnected = true;
                        connection      = netMsg.conn;
                        PushMessage(new JHSNetworkMessage
                        {
                            msgType = InternalMessages.CONNECTED,
                            conn    = netMsg.conn,
                            reader  = new JHSNetworkReader()
                        });
                    }
                }
            }
        }
Ejemplo n.º 7
0
 public bool Disconnect(JHSConnection con)
 {
     if (con != null)
     {
         uint conId = con.connectionId;
         JHSNetworkServer.PushMessage(new JHSNetworkMessage
         {
             msgType = InternalMessages.DISCONNECT,
             conn    = con,
             reader  = new JHSNetworkReader()
         });
         JHSStatisiticsManager.Remove(con);
         lock (m_Connections)
         {
             if (m_Connections.ContainsKey(conId))
             {
                 m_Connections.Remove(conId);
             }
         }
         con.Dispose();
     }
     return(true);
 }
Ejemplo n.º 8
0
        public void AcceptCallback(IAsyncResult ar)
        {
            // Get the socket that handles the client request.
            Socket        listener     = (Socket)ar.AsyncState;
            Socket        handler      = listener.EndAccept(ar);
            uint          connectionId = IncrementCount();
            JHSConnection per          = new JHSConnection
            {
                connectionId = connectionId
            };

            per.Init(false);
            per.SetHandlers(m_MessageHandlers);
            per.StartReceiving(handler);
            lock (m_Connections)
            {
                if (!m_Connections.ContainsKey(connectionId))
                {
                    m_Connections.Add(connectionId, per);
                }
            }
            // Signal the main thread to continue.
            _receiveSocket.BeginAccept(new AsyncCallback(AcceptCallback), _receiveSocket);
        }
 public static void Disconnect(JHSConnection con)
 {
     Instance.Discconnectx(con);
 }
Ejemplo n.º 10
0
 public static void Disconnect(JHSConnection con)
 {
     Instance.DisconnectClient(con);
 }