Пример #1
0
        ////处理连接
        //static void appServer_NewSessionConnected(AppSession session)
        //{
        //    session.Send("Welcome to SuperSocket Telnet Server");
        //}

        ////处理请求
        //static void appServer_NewRequestReceived(AppSession session, StringRequestInfo requestInfo)
        //{
        //    switch (requestInfo.Key.ToUpper())
        //    {
        //        case "1":
        //            {
        //                session.Send("123456789");

        //            }
        //            break;
        //        case "2":
        //            {
        //                session.Send("2222222222");
        //            }
        //            break;
        //        case "3":
        //            {
        //                session.Send("333333333333");
        //            }
        //            break;

        //    }
        //    //switch (requestInfo.Key.ToUpper())
        //    //{
        //    //    case ("ECHO"):
        //    //        session.Send(requestInfo.Body);
        //    //        break;

        //    //    case ("ADD"):
        //    //        session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
        //    //        break;

        //    //    case ("MULT"):

        //    //        var result = 1;

        //    //        foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
        //    //        {
        //    //            result *= factor;
        //    //        }

        //    //        session.Send(result.ToString());
        //    //        break;
        //    //}
        //}

        //public class TelnetSession : AppSession<TelnetSession>
        //{
        //    protected override void OnSessionStarted()
        //    {
        //        this.Send("Welcom to Supersocket Telnet Server");
        //    }

        //    protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        //    {
        //        this.Send("Unknow request");
        //    }

        //    protected override void HandleException(Exception e)
        //    {
        //        this.Send("Application error: {0}", e.Message);
        //    }

        //    protected override void OnSessionClosed(CloseReason reason)
        //    {
        //        //add you logics which will be executed after the session is closed
        //        base.OnSessionClosed(reason);
        //    }
        //}

        //public class TelnetServer : AppServer<TelnetSession>
        //{
        //    protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
        //    {
        //        return base.Setup(rootConfig, config);
        //    }

        //    protected override void OnStartup()
        //    {
        //        base.OnStartup();
        //    }

        //    protected override void OnStopped()
        //    {
        //        base.OnStopped();
        //    }
        //}

        private static void AgpsUbloxHandle(object source, ElapsedEventArgs e)
        {
            string host = "agps.u-blox.com";
            int    port = 46434;

            AgpsClient client = new AgpsClient();

            //string host = "121.199.26.185";
            //int port = 5000;
            Console.WriteLine("AgpsUbloxHandle");
            //string result = SocketSendReceive(host, port);
            client.StartClient(host, port);

            //MTK AGPS data
            MtkAgpsData mtkAgps = new MtkAgpsData();

            mtkAgps.update();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the agps client!");

            Console.ReadKey();
            Console.WriteLine();

            //测试代码
            //byte[] rsp = { 0x30, 0x00, 0x31, 0x00, 0x1D, 0x60, 0xD1, 0x79, 0x80, 0xA0, 0xA1 };
            //byte[] rsp1 = { 0x40, 0x00, 0x41, 0x00, 0x1D, 0x60, 0xD1, 0x79, 0x80, 0xB0, 0xB1, 0xC0, 0xCF, 0xFE, 0xFF };
            //string utfString = Encoding.UTF8.GetString(rsp, 0, rsp.Length);
            //string utfString1 = Encoding.ASCII.GetString(rsp, 0, rsp.Length);
            //string str = Encoding.GetEncoding(936).GetString(rsp, 0, rsp.Length);
            //Console.WriteLine(utfString);
            //Console.WriteLine(utfString1);
            //Console.WriteLine(str);
            //byte[] rsp2 = new byte[10];
            //Console.WriteLine(rsp2.Length);
            //List< byte > ls = new List<byte>();
            //ls.AddRange(rsp);
            //ls.AddRange(rsp1);
            //rsp2 = ls.ToArray();
            //Console.WriteLine(rsp2.Length);
            //ArrayList arrLi = new ArrayList();
            //arrLi.AddRange(rsp);
            //Console.WriteLine(arrLi.ToArray().Length);
            //arrLi.AddRange(rsp1);
            //Console.WriteLine(arrLi.ToArray().Length);
            //byte[] tmpRsp = { 0x60, 0xD1 };
            //var i = arrLi.IndexOf(tmpRsp);
            //Console.WriteLine(i);
            //byte tmpRsp1 = 0x60;
            //var j = arrLi.IndexOf(tmpRsp1);
            //Console.WriteLine(j);
            //Console.WriteLine(Array.IndexOf(rsp, tmpRsp));

            //// 注意是TelnetServer
            //var appServer = new TelnetServer();
            //appServer.Setup(2012);
            //// 开始监听
            //appServer.Start();
            //while (Console.ReadKey().KeyChar != 'q')
            //{
            //    Console.WriteLine();
            //    continue;
            //}
            //// 停止服务器。
            //appServer.Stop();

            //启动客户端
            string     host   = "agps.u-blox.com";
            int        port   = 46434;
            AgpsClient client = new AgpsClient();

            client.StartClient(host, port);
            Console.WriteLine("Ublox Agps data len {0}", AgpsClient.AgpsData.Length);

            //MTK AGPS data
            MtkAgpsData mtkAgps = new MtkAgpsData();

            mtkAgps.update();
            Console.WriteLine("Mtk Agps data len {0}", MtkAgpsData.Data.Length);

            //启动定时器,定时更新AGPS数据。
            System.Timers.Timer agpsUbloxTimer = new System.Timers.Timer();
            agpsUbloxTimer.AutoReset = true;
            agpsUbloxTimer.Enabled   = true;
            agpsUbloxTimer.Interval  = 600000;
            agpsUbloxTimer.Elapsed  += new System.Timers.ElapsedEventHandler(AgpsUbloxHandle);
            agpsUbloxTimer.Start();

            Console.WriteLine("Press any key to start the agps server!");
            Console.ReadKey();
            Console.WriteLine();

            //读取配置文件
            //ConfigurationSection accounts = config.AppSettings.Settings());
            //Console.WriteLine(accounts.ToString());
            //判断App.config配置文件中是否有key
            if (ConfigurationManager.AppSettings.HasKeys())
            {
                //List<string> theKeys = new List<string>();      //保存key的集合
                //List<string> theValues = new List<string>();    //保存value的集合
                ////遍历出所有的key并添加进thekeys集合
                //foreach (string theKey in ConfigurationManager.AppSettings.Keys)
                //{
                //    theKeys.Add(theKey);
                //}
                ////根据key遍历出所有的value并添加进theValues集合
                //for (int i = 0; i < theKeys.Count; i++)
                //{
                //    foreach (string theValue in ConfigurationManager.AppSettings.GetValues(theKeys[i]))
                //    {
                //        theValues.Add(theValue);
                //    }
                //}
                ////验证key和value
                //for (int i = 0; i < theKeys.Count; i++)
                //{
                //    Console.WriteLine("Account: {0}, {1}", theKeys[i], theValues[i]);
                //}
                //遍历出所有的key并添加进thekeys集合
                //foreach (string theKey in ConfigurationManager.AppSettings.Keys)
                //{
                //    Keys.Add(theKey);
                //}
                ////根据key遍历出所有的value并添加进theValues集合
                //for (int i = 0; i < Keys.Count; i++)
                //{
                //    foreach (string theValue in ConfigurationManager.AppSettings.GetValues(Keys[i]))
                //    {
                //        Pwds.Add(theValue);
                //    }
                //}
                //for (int i = 0; i < Keys.Count; i++)
                //{
                //    Console.WriteLine("Account: {0},{1}", Keys[i], Pwds[i]);
                //}
                foreach (string key in ConfigurationManager.AppSettings.Keys)
                {
                    string value = ConfigurationManager.AppSettings.GetValue(key);
                    KeyDic.Add(key, value);
                }
                foreach (KeyValuePair <string, string> kvp in KeyDic)
                {
                    Console.WriteLine("KeyDic: {0},{1}", kvp.Key, kvp.Value);
                }
            }

            // 通过工厂创建一个加载器。
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result : {0}!", result);
            if (log.IsDebugEnabled)
            {
                log.Debug("Start succ!");
            }
            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }
            // 停止服务器
            bootstrap.Stop();

            //var appServer = new AppServer();

            ////Setup the appServer
            //if (!appServer.Setup(2012)) //Setup with listening port
            //{
            //    Console.WriteLine("Failed to setup!");
            //    Console.ReadKey();
            //    return;
            //}

            //Console.WriteLine();

            ////Try to start the appServer
            //if (!appServer.Start())
            //{
            //    Console.WriteLine("Failed to start!");
            //    Console.ReadKey();
            //    return;
            //}

            //Console.WriteLine("The server started successfully, press key 'q' to stop it!");
            //appServer.NewSessionConnected += new SessionHandler<AppSession>(appServer_NewSessionConnected);
            //appServer.NewRequestReceived += new RequestHandler<AppSession, StringRequestInfo>(appServer_NewRequestReceived);

            //while (Console.ReadKey().KeyChar != 'q')
            //{
            //    Console.WriteLine();
            //    continue;
            //}

            ////Stop the appServer
            //appServer.Stop();

            //Console.WriteLine("The server was stopped!");
            //Console.ReadKey();
        }