示例#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
 public override void ClientSend(int channelId, ArraySegment <byte> segment)
 {
     // telepathy doesn't support allocation-free sends yet.
     // previously we allocated in Mirror. now we do it here.
     byte[] data = new byte[segment.Count];
     Array.Copy(segment.Array, segment.Offset, data, 0, segment.Count);
     client.Send(data);
 }
    public void Send(BADNetworkMessage networkMessage)
    {
        var data    = JsonConvert.SerializeObject(networkMessage);
        var encoded = Encoding.UTF8.GetBytes(data);
        var buffer  = new ArraySegment <Byte>(encoded, 0, encoded.Length);

        Debug.Log("send message");
        _client.Send(buffer);
    }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            // send a message to server
            //   client.Send(new byte[] { 0xFF });

            if (NickTB.Text == "")
            {
                TextPanel.Text += "Dear Senchi member, please enter your nickname :)\r\n";
                return;
            }

            string msg = NickTB.Text.ToString() + ": " + msgTB.Text.ToString();

            byte[] msgc = Encoding.Default.GetBytes(msg);

            client.Send(msgc);
            msgTB.Text = "";
            serverConnect();
        }
示例#5
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();
    }
示例#6
0
 public void SendNetworkMessageToServer(SNetworkMessage _message)
 {
     client.Send(Encoding.UTF8.GetBytes(JsonUtility.ToJson(_message)));
 }
示例#7
0
 public void Send(ArraySegment <byte> data)
 {
     _client.Send(data);
 }
示例#8
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;
                }
            }
        }
    }