private void client_OnReceive(ClientSocket sender, byte[] data)
        {
            var offset = 0;

            while (offset < data.Length)
            {
                ushort length = BitConverter.ToUInt16(data, offset);

                if (data.Length > length)
                {
                    var splitPacket = new byte[length];
                    Buffer.BlockCopy(data, offset, splitPacket, 0, length);
                    PacketHandler.Add(splitPacket, this);

                    offset += length;
                }
                else if (data.Length < length)
                {
                    throw new Exception("Erro data length contains " + data.Length + " bytes and length is " + length);
                }
                else // data.Length == length
                {
                    PacketHandler.Add(data, this);
                    offset += data.Length;
                }
            }
        }
        public GameClient(string ip, int port)
        {
            IP = ip;
            Port = port;

            socket = new ClientSocket();
            socket.OnConnect += client_OnConnect;
            socket.OnReceive += client_OnReceive;
            socket.OnDisconnect += client_OnDisconnect;
        }
 private void client_OnConnect(ClientSocket sender, object arg)
 {
     Console.WriteLine("Connected to the server");
 }