Akka.Interfaced.SlimSocket.Client.TcpConnection.SendPacket C# (CSharp) Method

SendPacket() public method

public SendPacket ( object packet ) : bool
packet object
return bool
        public bool SendPacket(object packet)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            if (_state != TcpState.Connected)
            {
                return false;
            }

            lock (_sendPacketQueue)
                _sendPacketQueue.Add(packet);

            if (_sendProcessing == false)
                ProcessSend();

            return true;
        }

Usage Example

        // BEWARE: CALLED BY WORK THREAD
        private void OnConnect(object sender)
        {
            _logger?.Trace("Connected.");

            if (string.IsNullOrEmpty(_token))
            {
                SetConnected();
            }
            else
            {
                _tcpConnection.SendPacket(new Packet
                {
                    Type    = PacketType.System,
                    Message = _token
                });

                SetState(ChannelStateType.TokenChecking);
            }
        }