Ejemplo n.º 1
0
        public virtual async Task <bool> SendToConnectionRawAsync(string message, IConnectionServer connection)
        {
            try
            {
                if (_handler != null &&
                    _handler.IsServerRunning &&
                    _connectionManager.IsConnectionOpen(connection))
                {
                    if (!await _handler.SendRawAsync(message, connection))
                    {
                        return(false);
                    }

                    await FireEventAsync(this, new TcpMessageServerEventArgs
                    {
                        Message          = message,
                        MessageEventType = MessageEventType.Sent,
                        Connection       = connection,
                        Packet           = new Packet
                        {
                            Data      = message,
                            Timestamp = DateTime.UtcNow
                        },
                    });

                    return(true);
                }
            }
            catch (Exception ex)
            {
                await FireEventAsync(this, new TcpErrorServerEventArgs
                {
                    Connection = connection,
                    Exception  = ex,
                    Message    = ex.Message
                });
            }

            return(false);
        }