コード例 #1
0
    void Awake()
    {
        Application.runInBackground = true;
        DontDestroyOnLoad(this);

        prot = new SimpleProtocolFilter();
        rpc  = new RPCParser();
        rpc.addRpcMethod("Add", Add);
        rpc.addRpcMethod("Screenshot", Screenshot);
        rpc.addRpcMethod("GetScreenSize", GetScreenSize);
        rpc.addRpcMethod("Dump", Dump);
        rpc.addRpcMethod("GetDebugProfilingData", GetDebugProfilingData);
        rpc.addRpcMethod("SetText", SetText);
        rpc.addRpcMethod("GetSDKVersion", GetSDKVersion);

        mRunning = true;

        server                  = new AsyncTcpServer(port);
        server.Encoding         = Encoding.UTF8;
        server.ClientConnected +=
            new EventHandler <TcpClientConnectedEventArgs> (server_ClientConnected);
        server.ClientDisconnected +=
            new EventHandler <TcpClientDisconnectedEventArgs> (server_ClientDisconnected);
        server.DatagramReceived +=
            new EventHandler <TcpDatagramReceivedEventArgs <byte[]> > (server_Received);
        server.Start();
        Debug.Log("Tcp server started");
    }
コード例 #2
0
    void Awake()
    {
        Application.runInBackground = true;
        DontDestroyOnLoad(this);
        prot = new SimpleProtocolFilter();
        rpc  = new RPCParser();
        rpc.addRpcMethod("isVRSupported", vr_support.isVRSupported);
        rpc.addRpcMethod("hasMovementFinished", vr_support.IsQueueEmpty);
        rpc.addRpcMethod("RotateObject", vr_support.RotateObject);
        rpc.addRpcMethod("ObjectLookAt", vr_support.ObjectLookAt);
        rpc.addRpcMethod("Screenshot", Screenshot);
        rpc.addRpcMethod("GetScreenSize", GetScreenSize);
        rpc.addRpcMethod("Dump", Dump);
        rpc.addRpcMethod("GetDebugProfilingData", GetDebugProfilingData);
        rpc.addRpcMethod("SetText", SetText);

        rpc.addRpcMethod("GetSDKVersion", GetSDKVersion);

        mRunning = true;

        for (int i = 0; i < 5; i++)
        {
            this.server                  = new AsyncTcpServer(port + i);
            this.server.Encoding         = Encoding.UTF8;
            this.server.ClientConnected +=
                new EventHandler <TcpClientConnectedEventArgs>(server_ClientConnected);
            this.server.ClientDisconnected +=
                new EventHandler <TcpClientDisconnectedEventArgs>(server_ClientDisconnected);
            this.server.DatagramReceived +=
                new EventHandler <TcpDatagramReceivedEventArgs <byte[]> >(server_Received);
            try
            {
                this.server.Start();
                Debug.Log(string.Format("Tcp server started and listening at {0}", server.Port));
                break;
            }
            catch (SocketException e)
            {
                Debug.Log(string.Format("Tcp server bind to port {0} Failed!", server.Port));
                Debug.Log("--- Failed Trace Begin ---");
                Debug.LogError(e);
                Debug.Log("--- Failed Trace End ---");
                // try next available port
                this.server = null;
            }
        }
        if (this.server == null)
        {
            Debug.LogError(string.Format("Unable to find an unused port from {0} to {1}", port, port + 5));
        }
        vr_support.ClearCommands();
    }
コード例 #3
0
    void Awake()
    {
        Application.runInBackground = true;
        DontDestroyOnLoad(this);

        prot = new SimpleProtocolFilter();
        rpc  = new RPCParser();
        rpc.addRpcMethod("Add", Add);
        rpc.addRpcMethod("Screenshot", Screenshot);
        rpc.addRpcMethod("GetScreenSize", GetScreenSize);
        rpc.addRpcMethod("Dump", Dump);
        rpc.addRpcMethod("GetDebugProfilingData", GetDebugProfilingData);
        rpc.addRpcMethod("SetText", SetText);
        rpc.addRpcMethod("GetSDKVersion", GetSDKVersion);

        mRunning = true;

        for (int i = 0; i < 5; i++)
        {
            this.server                  = new AsyncTcpServer(port + i);
            this.server.Encoding         = Encoding.UTF8;
            this.server.ClientConnected +=
                new EventHandler <TcpClientConnectedEventArgs> (server_ClientConnected);
            this.server.ClientDisconnected +=
                new EventHandler <TcpClientDisconnectedEventArgs> (server_ClientDisconnected);
            this.server.DatagramReceived +=
                new EventHandler <TcpDatagramReceivedEventArgs <byte[]> > (server_Received);
            try {
                this.server.Start();
                Debug.Log(string.Format("Tcp server started and listening at {0}", server.Port));
                break;
            } catch (SocketException e) {
                // try next available port
                this.server = null;
            }
        }
        if (!this.server)
        {
            Debug.LogError(string.Format("Unable to find an unused port from {0} to {1}", port, port + 5));
        }
    }