public void Send(int messageTypeID, byte[] message)
        {
            if (!this.ClientHandler.Connected)
            {
                Close(false);
                return;
            }
            byte[] messageType = BitConverter.GetBytes(messageTypeID);
            byte[] messageSize = BitConverter.GetBytes(message.Length);

            var fullMessage = new List <byte>();

            fullMessage.AddRange(messageType);
            fullMessage.AddRange(messageSize);
            fullMessage.AddRange(message);
            int checkSum = 0;

            //checksum
            unchecked
            {
                for (int i = 0; i < fullMessage.Count; i++)
                {
                    checkSum = checkSum ^ fullMessage[i];
                }
            }
            fullMessage.InsertRange(0, BitConverter.GetBytes(checkSum));
            var byteData = fullMessage.ToArray();

            ClientHandler.Send(byteData);

            if (SendMessageCompleted != null && messageTypeID != (int)Common.SocketMessageTypes.Ping)
            {
                SendMessageCompleted.Invoke(this);
            }
        }
        public void Send(int messageTypeID, byte[] message)
        {
            if (!this.ClientHandler.Connected)
            {
                Close(false);
                return;
            }
            byte[] messageType = BitConverter.GetBytes(messageTypeID);
            byte[] messageSize = BitConverter.GetBytes(message.Length);

            var fullMessage = new List <byte>();

            fullMessage.AddRange(messageType);
            fullMessage.AddRange(messageSize);
            fullMessage.AddRange(message);

            int checkSum = 0;

            //checksum
            unchecked
            {
                for (int i = 4; i < fullMessage.Count; i++)
                {
                    checkSum = checkSum ^ fullMessage[i];
                }
            }
            fullMessage.InsertRange(0, BitConverter.GetBytes(checkSum));

            var byteData = fullMessage.ToArray();

            //send precisa ser sincrono para garantir que não vai ter merda depois
            ClientHandler.Send(byteData);

            if (SendMessageCompleted != null && (messageTypeID != SocketListener.PingMessageID))
            {
                SendMessageCompleted.Invoke(this);
            }
        }