예제 #1
0
    public static void startCon()
    {
        sc = new vesal_network.vesal_socket();

        if (sc.connect("127.0.0.1", port))
        {
            // DebugLog.DebugLogInfo("I'm Unity,Save me!");
            // int tmp = sc._sock.Send(Encoding.UTF8.GetBytes("I'm Unity,Save me!"), SocketFlags.None);
        }
        else
        {
            //连接失败重连
            startCon();
        }
        pc = new vesal_network.packet();

        byte[] bytes = new byte[1024];
        while (true)
        {
            if (sc != null && sc._sock != null && !sc._sock.Poll(1000, SelectMode.SelectRead))
            {
                int    receiveNumber = sc._sock.Receive(bytes);
                string message       = Encoding.UTF8.GetString(bytes, 0, receiveNumber);
                switch (message)
                {
                case "quit":
                    stopThread();
                    break;

                case "":
                    UnityEngine.Debug.Log("linsten");
                    break;

                default:
                    UnityEngine.Debug.Log("得到参数:" + message);
                    // if(PublicClass.appOpera!=null)
                    //     PublicClass.appOpera.Get_app(message);
                    rcvMessage = message;
                    break;
                }

                // UnityEngine.Debug.Log(string.Format(" 接收客户端{0}消息{1}", sc._sock.RemoteEndPoint.ToString(), message));
                //         try
                //         {
                //             rcvMessage = "断开连接";
                //             thread.Abort();
                //             sc.close();
                //             break;
                //         }
                //         catch
                //         {
                //         }
                // int tmp = sc._sock.Send(Encoding.UTF8.GetBytes(message));
                // UnityEngine.Debug.Log(tmp + "--" + message.Equals("disconnect") + "--" + (message == "disconnect"));
            }
            //Thread.SpinWait(1);
        }
    }
예제 #2
0
    public static void Send_message(string str)
    {
        sc = new vesal_network.vesal_socket();

        if (sc.connect("127.0.0.1", port))
        {
            // DebugLog.DebugLogInfo("I'm Unity,Save me!");
            int tmp = sc._sock.Send(Encoding.UTF8.GetBytes(str), SocketFlags.None);
        }
        else
        {
            //连接失败重连
            Send_message(str);
        }
    }
예제 #3
0
    private void FixedUpdate()
    {
        if (PPTGlobal.PPTEnv != PPTGlobal.PPTEnvironment.plugin)
        {
            return;
        }
        try
        {
            ArrayList listenList = new ArrayList();
            ArrayList clientList = new ArrayList();
            listenList.Add(_listen_sock._sock);
            Socket.Select(listenList, null, null, 1000);
            if (listenList.Count > 0)
            {
                vesal_network.vesal_socket sok = new vesal_network.vesal_socket();
                sok._sock = _listen_sock.accept();
                _client_socks.Add(sok);
                vesal_log.vesal_write_log("peer connect!");
            }

            for (int i = 0; i < _client_socks.Count; i++)
            {
                clientList.Add(((vesal_network.vesal_socket)_client_socks[i])._sock);
            }
            if (clientList.Count > 0)
            {
                Socket.Select(clientList, null, null, 1000);
            }
            for (int i = 0; i < clientList.Count; i++)
            {
                int  index      = find_sock_seted((Socket)clientList[i]);
                bool get_packet = false;
                try
                {
                    packet pk = new packet();
                    //((vesal_network.vesal_socket)_client_socks[index])._get_header = true;
                    get_packet = ((vesal_network.vesal_socket)_client_socks[index]).recv_packet(ref pk);
                    if (get_packet)
                    {
                        byte[] buff = new byte[pk._data_len];
                        for (int j = 0; j < pk._data_len; j++)
                        {
                            buff[j] = pk._data[j];
                        }
                        string str = System.Text.Encoding.Default.GetString(buff);
#if UNITY_EDITOR
                        UnityEngine.Debug.LogError("str:" + str);
#endif
                        String log_content = String.Format("get pack {0}:{1}", pk._cmd_code, str);
                        vesal_log.vesal_write_log(log_content);
                        if (pk._cmd_code == (byte)VESAL_CMD_CODE.MSG_CMD)
                        {
                            ChangeModel(str);

                            ((vesal_network.vesal_socket)_client_socks[index]).send_confirm();
                            vesal_log.vesal_write_log("change model.");
                        }
                        else if (pk._cmd_code == (byte)VESAL_CMD_CODE.CTRL_CMD)
                        {
                            if (str == "shutdown")
                            {
                                vesal_log.vesal_write_log("I will exit.");
                                // 首先发送确认消息。
                                ((vesal_network.vesal_socket)_client_socks[index]).send_confirm();
                                // 增加进程退出代码。
                                //Application.runInBackground = true;
                                Process.GetCurrentProcess().Kill();
                                //Application.Quit();
                            }
                            else if (str == "min")
                            {
                                //最小化
                                GetComponent <WindowControl>().WindowMin();
                            }
                        }
                        else if (pk._cmd_code == (byte)VESAL_CMD_CODE.WIN_HWND)
                        {
                            //获得PPT播放窗口和PPT页码
                            string[] res = str.Split(',');
                            if (res.Count() > 1)
                            {
                                windows_ppt = new IntPtr(int.Parse(res[0]));
                                pageno_ppt  = int.Parse(res[1]);
                                pageNo      = pageno_ppt;
                                pptName     = res[3] + "_" + res[2];
                                //if (res.Count() >= 8)
                                //{
                                //    int x = int.Parse(res[4]);
                                //    int y = int.Parse(res[5]);
                                //    int width = int.Parse(res[6]);
                                //    int height = int.Parse(res[7]);

                                //    int HWND_TOPMOST = -1;
                                //    int SWP_FRAMECHANGED = 0x0020;
                                //    int SWP_DRAWFRAME = SWP_FRAMECHANGED;
                                //    IntPtr hw= FindWindow(null, "PPTPlugin");
                                //    SetWindowPos(  hw, -1, x, y, width, height, SWP_DRAWFRAME);
                                //}
                            }
                        }
                    }
                }
                catch (Exception e)
                {
#if UNITY_EDITOR
                    UnityEngine.Debug.Log(e.Message);
                    UnityEngine.Debug.Log(e.StackTrace);
#endif
                    // link broken.
                    ((vesal_network.vesal_socket)_client_socks[index]).close();
                    remove_sock_list((Socket)clientList[i]);
                    vesal_log.vesal_write_log("link broken");
                }
            }
        }
        catch (Exception e)
        {
#if UNITY_EDITOR
            UnityEngine.Debug.Log(e.Message);
            UnityEngine.Debug.Log(e.StackTrace);
#endif
        }
    }
예제 #4
0
    private void FixedUpdate()
    {
        try
        {
            ArrayList listenList = new ArrayList();
            ArrayList clientList = new ArrayList();
            listenList.Add(_listen_sock._sock);
            Socket.Select(listenList, null, null, 1000);
            if (listenList.Count > 0)
            {
                vesal_network.vesal_socket sok = new vesal_network.vesal_socket();
                sok._sock = _listen_sock.accept();
                _client_socks.Add(sok);
                Debug.Log("peer connect!");
            }

            for (int i = 0; i < _client_socks.Count; i++)
            {
                clientList.Add(((vesal_network.vesal_socket)_client_socks[i])._sock);
            }
            if (clientList.Count <= 0)
            {
                return;
            }
            Socket.Select(clientList, null, null, 1000);
            for (int i = 0; i < clientList.Count; i++)
            {
                int  index      = find_sock_seted((Socket)clientList[i]);
                bool get_packet = false;
                try
                {
                    packet pk = new packet();
                    get_packet = ((vesal_network.vesal_socket)_client_socks[index]).recv_packet(ref pk);
                    if (get_packet)
                    {
                        byte[] buff = new byte[pk._data_len];
                        for (int j = 0; j < pk._data_len; j++)
                        {
                            buff[j] = pk._data[j];
                        }
                        string str         = System.Text.Encoding.Default.GetString(buff);
                        string log_content = string.Format("get pack {0}:{1}", pk._cmd_code, str);
                        Debug.Log(log_content);
                        if (pk._cmd_code == (byte)VESAL_CMD_CODE.MSG_CMD)
                        {
                            Debug.Log(str);
                            if (str == "loadScene")
                            {
                                SceneManager.LoadScene("WeiKePlayer");
                            }
                        }
                        else if (pk._cmd_code == (byte)VESAL_CMD_CODE.CTRL_CMD)
                        {
                        }
                        else if (pk._cmd_code == (byte)VESAL_CMD_CODE.WIN_HWND)
                        {
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                    // link broken.
                    ((vesal_network.vesal_socket)_client_socks[index]).close();
                    remove_sock_list((Socket)clientList[i]);
                    Debug.Log("link broken");
                }
            }
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
        }
    }