示例#1
0
        public async Task OnRecv(MemoryStream stream, int count)
        {
            if (count == 0)
            {
                await OnDisConnect();

                return;
            }
            //路由消息
            var buf = new byte[count];

            stream.Read(buf, 0, count);
            var txt = System.Text.Encoding.UTF8.GetString(buf);

            var json = JObject.Parse(txt);
            var cmd  = json["cmd"].ToString();
            var vars = (JArray)json["vars"];

            if (cmd == "init")
            {
                this.winid = (int)vars[0];
                bindwin    = WindowRemote.Get(this.winid);
                bindwin.BindSession(this);
            }

            if (bindwin == null)
            {
                Console.WriteLine("error socket msg:" + txt);
            }
            else
            {
                bindwin.OnRecv(cmd, vars);
            }
        }
示例#2
0
 static void RecordWin(WindowRemote win)
 {
     if (allwindow == null)
     {
         allwindow = new Dictionary <int, WindowRemote>();
     }
     allwindow[win.winid] = win;
 }
示例#3
0
        public static async Task <WindowRemote> Create(WebWindow.WindowMgr mgr, WindowCreateOption op)
        {
            if (!mgr.hadInit)
            {
                throw new Exception("windowmgr has not inited.");
            }

            var url      = mgr.urlWin;
            var windowid = await mgr.window_create(op, url);

            var win = new WindowRemote(mgr, windowid);

            RecordWin(win);
            while (!win.hasInit)
            {
                await Task.Delay(100);
            }
            return(win);
        }