Beispiel #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);
        }
Beispiel #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();
        }
Beispiel #3
0
        public static void HandleSocketData(int index, byte[] data)
        {
            //creating a new instance of 'SocketBuffer' to read out the packet.
            SocketBuffer buffer = new SocketBuffer();

            //writing incoming packet to the buffer.
            buffer.WriteBytes(data);
            //reads out the packet to see which packet we got.
            int packet = buffer.ReadInteger();

            //closes the buffer.
            buffer.Dispose();
            //checking if we are listening to that packet in the _packets Dictionary.
            if (_packets.TryGetValue(packet, out Packets _packet))
            {
                //checks which Method is assigned to the packet and executes it,
                //index: the socket which sends the data
                //data: the packet byte [] with the information.
                _packet.Invoke(index, data);
            }
        }