Connect() 공개 정적인 메소드

public static Connect ( String ip, int port, String user, String paswd, String database ) : bool
ip String
port int
user String
paswd String
database String
리턴 bool
예제 #1
0
파일: Program.cs 프로젝트: tangfengray/soul
        static void Main(string[] args)
        {
            //日志路径
            Log.Instance().Init("./DBServer");
            //异常
            GameBase.Core.GlobalException.InitException();
            MemIniFile ini = new MemIniFile();

            if (!ini.LoadFromFile(TextDefine.GoldConfig))
            {
                return;
            }
            //载入名称过滤文件
            if (!Filter.Instance().LoadFilterNameFile(TextDefine.CONFIG_FILTERNAME))
            {
                Log.Instance().WriteLog("载入名称过滤文件失败");
            }
            //连接mysql
            String sip       = ini.ReadValue(TextDefine.MysqlSection, "IP", "127.0.0.1");
            int    nPort     = ini.ReadValue(TextDefine.MysqlSection, "Port", 3306);
            String sUser     = ini.ReadValue(TextDefine.MysqlSection, "User", "root");
            String sPaswd    = ini.ReadValue(TextDefine.MysqlSection, "Passwd", "test");
            String sDataBase = ini.ReadValue(TextDefine.MysqlSection, "database", "soul");

            if (!MysqlConn.Connect(sip, nPort, sUser, sPaswd, sDataBase))
            {
                Log.Instance().WriteLog("connect mysql error!");
                return;
            }

            LoadGameKernel();
            //启动tcp服务器=
            sip                   = ini.ReadValue(TextDefine.DBServerSestion, "IP", "0.0.0.0");
            nPort                 = ini.ReadValue(TextDefine.DBServerSestion, "Port", 1500);
            mTcpServer            = new TcpServer();
            mTcpServer.onConnect += new TcpServerEvent.OnConnectEventHandler(OnConnect);
            mTcpServer.onReceive += new TcpServerEvent.OnReceiveEventHandler(OnReceive);
            mTcpServer.onClose   += new TcpServerEvent.OnCloseEventHandler(OnClose);
            if (!mTcpServer.Start(sip, nPort))
            {
                Console.WriteLine("start server error!");
                MysqlConn.Dispose();
                return;
            }
            //启动工作线程-

            Thread logicThread = new Thread(new ThreadStart(LogicRun));

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

            while (true)
            {
                String sCommand = Console.ReadLine();
                if (sCommand == "quit" ||
                    sCommand == "exit")
                {
                    break;
                }
            }
            MysqlConn.Dispose();
        }