예제 #1
0
    void Update()
    {
        // client
        if (client.Connected)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                client.Send(new byte[] { 0x1 });
            }

            // show all new messages
            Telepathy.Message msg;
            while (client.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Debug.Log("Connected");
                    break;

                case Telepathy.EventType.Data:
                    Debug.Log("Data: " + BitConverter.ToString(msg.data));
                    break;

                case Telepathy.EventType.Disconnected:
                    Debug.Log("Disconnected");
                    break;
                }
            }
        }

        // server
        if (server.Active)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                server.Send(0, new byte[] { 0x2 });
            }

            // show all new messages
            Telepathy.Message msg;
            while (server.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Debug.Log(msg.connectionId + " Connected");
                    break;

                case Telepathy.EventType.Data:
                    Debug.Log(msg.connectionId + " Data: " + BitConverter.ToString(msg.data));
                    break;

                case Telepathy.EventType.Disconnected:
                    Debug.Log(msg.connectionId + " Disconnected");
                    break;
                }
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        // client
        if (client.Connected)
        {
            //client.Send(utf8.GetBytes("HV " + Hoz.ToString() + " " + Vert.ToString()));

            // show all new messages
            Telepathy.Message msg;
            while (client.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Debug.Log("Connected");
                    break;

                case Telepathy.EventType.Data:
                    ProcessData(msg);
                    //Debug.Log("Server Sent: " + utf8.GetString(msg.data));
                    break;

                case Telepathy.EventType.Disconnected:
                    Debug.Log("Disconnected");
                    break;
                }
            }
        }
    }
예제 #3
0
    private void Update()
    {
        if (hudPoint.enable && currentTransform != null)
        {
            hudPoint.SetPoint(currentTransform.TransformPoint(localPos));
        }
        if (client == null)
        {
            return;
        }
        if (!client.Connected)
        {
            Error.ShowError(startScene, "Server Disconnected");
            return;
        }

        Telepathy.Message msg;
        while (client.GetNextMessage(out msg))
        {
            switch (msg.eventType)
            {
            case Telepathy.EventType.Connected:
                break;

            case Telepathy.EventType.Data:
                SetPosition setPosition = DataParser.DeserializeObject <SetPosition>(msg.data);
                if (setPosition != null)
                {
                    process(setPosition);
                    break;
                }
                SetModel setModel = DataParser.DeserializeObject <SetModel>(msg.data);
                if (setModel != null)
                {
                    process(setModel);
                    break;
                }
                FileObject fileObject = DataParser.DeserializeObject <FileObject>(msg.data);
                if (fileObject != null)
                {
                    process(fileObject);
                    break;
                }

                break;

            case Telepathy.EventType.Disconnected:
                Error.ShowError(startScene, "Server Disconnected");
                break;
            }
        }
    }
예제 #4
0
    static void Main(string[] args)
    {
        client = new Telepathy.Client();
        client.Connect("localhost", 1337);

        Task.Run(() =>
        {
            while (client.Connected)
            {
                Telepathy.Message msg;
                while (client.GetNextMessage(out msg))
                {
                    // clientの場合、msg.connectionIdは常に0が格納されている
                    switch (msg.eventType)
                    {
                    case Telepathy.EventType.Connected:
                        Console.WriteLine("Telepathy.EventType.Connected : msg.connectionId=" + msg.connectionId);
                        break;

                    case Telepathy.EventType.Data:
                        Console.WriteLine("Telepathy.EventType.Data : msg.connectionId=" + msg.connectionId + ", msg.data" + System.Text.Encoding.UTF8.GetString(msg.data));
                        break;

                    case Telepathy.EventType.Disconnected:
                        Console.WriteLine("Telepathy.EventType.Disconnected : msg.connectionId=" + msg.connectionId);
                        break;
                    }
                }
            }
        });

        bool break_flag = false;

        while (break_flag == false)
        {
            ConsoleKey k = Console.ReadKey().Key;
            switch (k)
            {
            case ConsoleKey.Spacebar:
                Console.WriteLine("send massage from client...");
                client.Send(System.Text.Encoding.UTF8.GetBytes("send message from server..."));
                break;

            case ConsoleKey.Escape:
                break_flag = true;
                break;
            }
        }

        client.Disconnect();
    }
예제 #5
0
        public void serverConnect()
        {
            while (client.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Console.WriteLine("Connected");
                    ConnectCheck.Text      = "CONNECTED!";
                    ConnectCheck.ForeColor = Color.Snow;

                    break;

                case Telepathy.EventType.Data:     //msg taken

                    string ascii = Encoding.ASCII.GetString(msg.data);

                    if (!ascii.Contains("cls"))
                    {
                        TextPanel.Text += ascii + "\r\n";
                    }
                    else
                    {
                        TextPanel.Text = "";
                    }
                    System.Media.SoundPlayer player = new System.Media.SoundPlayer("sounds/nya.wav");
                    player.Play();


                    break;

                case Telepathy.EventType.Disconnected:
                    Console.WriteLine("Disconnected");
                    ConnectCheck.Text      = "CONNECTION ERROR!";
                    ConnectCheck.ForeColor = Color.Snow;
                    break;
                }
            }
        }
예제 #6
0
    void Update()
    {
        // client
        if (client.Connected)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                client.Send(new byte[] { 0x1 });

                //client.Send(Telepathy.Utils.StringToBytes(GameObject.Find("PlayerObject(Clone)").name)); // sends the players name as a byte[]
                //byte[] bytesvalue = Telepathy.Utils.StringToBytes(GameObject.Find("PlayerObject").name);
            }
            if (Input.GetKeyDown(KeyCode.LeftAlt))
            {
                GameObject.Instantiate(SquarePrefab, Vector3.zero, Quaternion.identity);
            }
            // show all new messages
            Telepathy.Message msg;
            while (client.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Debug.Log("Connected");
                    break;

                case Telepathy.EventType.Data:
                    Debug.Log("Data: " + BitConverter.ToString(msg.data));
                    break;

                case Telepathy.EventType.Disconnected:
                    Debug.Log("Disconnected");
                    break;
                }
            }
        }

        // server
        if (server.Active)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                server.Send(0, new byte[] { 0x2 });
            }

            // show all new messages
            Telepathy.Message msg;
            while (server.GetNextMessage(out msg))
            {
                switch (msg.eventType)
                {
                case Telepathy.EventType.Connected:
                    Debug.Log(msg.connectionId + " Connected");
                    break;

                case Telepathy.EventType.Data:
                    Debug.Log(msg.connectionId + " Data: " + BitConverter.ToString(msg.data));
                    break;

                case Telepathy.EventType.Disconnected:
                    Debug.Log(msg.connectionId + " Disconnected");
                    break;
                }
            }
        }
    }