Exemplo n.º 1
0
        //Handles the ChatMsg Packet you have assigned at "InitPackets"
        private static void HandleChatMsg(int index, byte[] data)
        {
            //Creates a new instance of the buffer to read out the packet.
            SocketBuffer buffer = new SocketBuffer();

            //writes the packet into a list to make it avaiable to read it out.
            buffer.WriteBytes(data);
            //INFO: You always have to read out the data as you did send it.
            //In this case you always have to first to read out the packet identifier.
            int packetIdentify = buffer.ReadInteger();
            //In the server side you now send a string as next so you have to read out the string as next.
            string msg = buffer.ReadString();

            //print out the string msg you did send from the server.
            Console.WriteLine("Got Packet Nr '{0}' with message: '{1}' from connection Nr: '{2}'", packetIdentify, msg, index);
        }
Exemplo n.º 2
0
        //Handles the ChatMsg Packet you have assigned at "InitPackets"
        private static void HandleChatMsg(byte[] data)
        {
            //Creates a new instance of the buffer to read out the packet.
            SocketBuffer buffer = new SocketBuffer();

            //writes the packet into a list to make it avaiable to read it out.
            buffer.WriteBytes(data);
            //INFO: You always have to read out the data as you did send it.
            //In this case you always have to first to read out the packet identifier.
            int packetIdentify = buffer.ReadInteger();
            //In the server side you now send a string as next so you have to read out the string as next.
            string msg = buffer.ReadString();

            //print out the string msg you did send from the server.
            Console.WriteLine("Got Packet Nr '{0}' with message: '{1}'", packetIdentify, msg);
            //we have received a welcome message now send a packet back to server to say thank you!
            SocketSend.SendThankYou();
        }