Beispiel #1
0
        /// <summary>
        /// Send a message to the client.
        /// </summary>
        /// <param name="packet">The message</param>
        /// <returns>Number of byte sended</returns>
        public int Send(Utils.Objects.Packet packet)
        {
            if (!_sock.Connected) return -1;

            try
            {
                int sended = _sock.Send(packet.Pack().ToArray());
                Utils.MyConsole.WriteLine
                    (
                        _ip + ": " + packet.ID + " (length: " + sended + ")",
                        ConsoleType.Send, ConsoleWriter.Game
                    );
                return sended;
            }
            catch (SocketException ex)
            {
                Utils.MyConsole.WriteLine
                    (
                        "Fail send data. " + ex.Message,
                        ConsoleType.Error, ConsoleWriter.Game
                    );
                Close();
                return -1;
            }
            catch (Exception ex)
            {
                Utils.MyConsole.WriteLine
                    (
                        ex,
                        ConsoleWriter.Game
                    );
                Close();
                return -1;
            }
        }