Connect() public method

public Connect ( String ip, int port ) : void
ip String
port int
return void
Example #1
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./LogicServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            m_DicSession = new Dictionary <Socket, GameBase.Network.GameSession>();
            m_DicSession.Clear();

            String sIP   = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalPortKey, TextDefine.LoginServerPort);

            m_Key             = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey, System.Environment.TickCount);
            m_Key2            = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey2, System.Environment.TickCount);
            m_GameServerIP    = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            m_GameServerPort  = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);
            server            = new TcpServer();
            server.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            server.onClose   += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!server.Start(sIP, nPort))
            {
                Console.WriteLine("start server error!");
                return;
            }

            //连接dbserver
            mDBPacket = new InternalPacket();
            GenerateKey.Init(m_Key, m_Key2);
            sIP                   = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            nPort                 = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);
            mTcpClient            = new GameBase.Network.TcpClient();
            mTcpClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnect);
            mTcpClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceive);
            mTcpClient.onClose   += new TcpClientEvent.OnCloseEventHandler(OnDBClose);
            mTcpClient.Connect(sIP, nPort);
            //逻辑处理
            Thread logicThread = new Thread(new ThreadStart(LogicTimer));

            logicThread.IsBackground = true;
            logicThread.Start();


            while (true)
            {
                String command = Console.ReadLine();
                if (command == "exit")
                {
                    break;
                }
            }
        }
Example #2
0
        public void Init()
        {
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                Log.Instance().WriteLog("load golbalconfig error!");
                return;
            }
            //连接dbserver的客户 InternalPacket
            mDBPacket = new InternalPacket();
            mTcpDBClient = new GameBase.Network.TcpClient();
            mTcpDBClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnectEventHandler);
            mTcpDBClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceiveEventHandler);
            mTcpDBClient.onClose += new TcpClientEvent.OnCloseEventHandler(OnDBClose);

            String sIP  = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int nPort = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);
            mTcpDBClient.Connect(sIP, nPort);
        }
Example #3
0
        public void Init()
        {
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                Log.Instance().WriteLog("load golbalconfig error!");
                return;
            }
            //连接dbserver的客户 InternalPacket
            mDBPacket               = new InternalPacket();
            mTcpDBClient            = new GameBase.Network.TcpClient();
            mTcpDBClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnectEventHandler);
            mTcpDBClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceiveEventHandler);
            mTcpDBClient.onClose   += new TcpClientEvent.OnCloseEventHandler(OnDBClose);

            String sIP   = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int    nPort = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);

            mTcpDBClient.Connect(sIP, nPort);
        }
Example #4
0
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./LogicServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();
            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            m_DicSession = new Dictionary<Socket, GameBase.Network.GameSession>();
            m_DicSession.Clear();

            String sIP = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalIPKey, TextDefine.NormalIP);
            int nPort = ini.ReadValue(TextDefine.LogicServerSection, TextDefine.NormalPortKey, TextDefine.LoginServerPort);
            m_Key = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey, System.Environment.TickCount);
            m_Key2 = ini.ReadValue(TextDefine.GlobalSection, TextDefine.EncodeKey2, System.Environment.TickCount);
            m_GameServerIP = ini.ReadValue(TextDefine.GameServerSetion,TextDefine.NormalIPKey, TextDefine.NormalIP);
            m_GameServerPort = ini.ReadValue(TextDefine.GameServerSetion, TextDefine.NormalPortKey, TextDefine.GameServerPort);
            server = new TcpServer();
            server.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            server.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            server.onClose += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!server.Start(sIP, nPort))
            {
                Console.WriteLine("start server error!");
                return;
            }

            //连接dbserver
            mDBPacket = new InternalPacket();
            GenerateKey.Init(m_Key, m_Key2);
            sIP = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalIPKey, TextDefine.NormalIP);
            nPort = ini.ReadValue(TextDefine.DBServerSestion, TextDefine.NormalPortKey, TextDefine.DBServerPort);
            mTcpClient = new GameBase.Network.TcpClient();
            mTcpClient.onConnect += new TcpClientEvent.OnConnectEventHandler(OnDBConnect);
            mTcpClient.onReceive += new TcpClientEvent.OnReceiveEventHandler(OnDBReceive);
            mTcpClient.onClose += new TcpClientEvent.OnCloseEventHandler(OnDBClose);
            mTcpClient.Connect(sIP, nPort);
            //逻辑处理
            Thread logicThread = new Thread(new ThreadStart(LogicTimer));
            logicThread.IsBackground = true;
            logicThread.Start();

            while (true)
            {
               String command = Console.ReadLine();
               if (command == "exit")
               {
                   break;
               }
            }
        }