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); } }