Exemple #1
0
    public void SendChat()
    {
        inputString = inputMsg.GetComponent <InputField>().text;
        if (inputString == "")
        {
            return;
        }
        // 聊天数据包
        Chat.ChatProto proto = new Chat.ChatProto();
        proto.userName = this.inputName;
        proto.chatMsg  = inputString;
        NetPacket p = new NetPacket();

        p.BeginWrite("chat");
        p.WriteObject <Chat.ChatProto>(proto);
        p.EncodeHeader();
        clientPeer.Send(p);

        // 清空消息
        if (queue.Count > 14)
        {
            queue.Dequeue();
        }
        queue.Enqueue(proto.userName + ": " + inputString + "\n");
        Que2Str();
        hisMsgTextField.text = hisMsg;
        inputMsg.GetComponent <InputField>().text = "";
    }
Exemple #2
0
    //send chat message
    public void SendChat()
    {
        //pack message in a packet and send
        Chat.ChatProto proto = new Chat.ChatProto();
        proto.userName = "******";
        proto.chatMsg  = inputString;
        NetPacket p = new NetPacket();

        p.BeginWrite("chat");
        p.WriteObject <Chat.ChatProto>(proto);
        p.EncodeHeader();
        clientPeer.send(p);

        inputString = "";
    }
Exemple #3
0
    /*
     * void OnGUI()
     * {
     *  // 显示收到的聊天记录
     *  GUI.Label(new Rect(5, 5, 200, 30), revString);
     *
     *  // 输入聊在消息
     *  inputString = GUI.TextField(new Rect(Screen.width * 0.5f - 200, Screen.height * 0.5f - 20, 400, 40), inputString);
     *
     *  // 发送聊天消息
     *  if ( GUI.Button( new Rect( Screen.width*0.5f-100,Screen.height*0.65f,200,30),"发送消息") )
     *  {
     *      // 向服务器发送聊天消息
     *      SendChat();
     *  }
     * }
     */
    // 发送聊天消息
    void SendChat()
    {
        // 聊天数据包
        Chat.ChatProto proto = new Chat.ChatProto();
        proto.userName = "******";
        proto.chatMsg  = inputText.text;

        NetPacket p = new NetPacket();

        p.BeginWrite("chat");
        p.WriteObject <Chat.ChatProto>(proto);
        p.EncodeHeader();

        clientPeer.Send(p);
        //清空输入框
        inputText.text = "";
    }
Exemple #4
0
    public void SendMessage(string msg)
    {
        Chat.ChatProto proto = new Chat.ChatProto();
        proto.userName = "******";
        proto.chatMsg  = msg;

        NetPacket p = new NetPacket();

        p.BeginWrite("chat");
        p.WriteObject <Chat.ChatProto>(proto);
        p.EncodeHeader();

        foreach (Socket sk in peerList)
        {
            server.Send(sk, p);
        }
    }
Exemple #5
0
        //send message to peers
        public void OnChat(NetPacket packet)
        {
            //display chat
            Chat.ChatProto proto = packet.ReadObject <Chat.ChatProto>();
            if (proto != null)
            {
                Console.WriteLine(proto.userName + ": " + proto.chatMsg);
            }

            packet.BeginWrite("chat");
            packet.WriteObject <Chat.ChatProto>(proto);
            packet.EncodeHeader();

            foreach (Socket sk in peerList)
            {
                server.Send(sk, packet);
            }
        }