예제 #1
0
 public void Send(string packet)
 {
     try
     {
         if (_connectionFactor)
         {
             _socket.Write(packet);
         }
     }
     catch (Exception)
     {
         Console.WriteLine("Failed sending packet.");
     }
 }
예제 #2
0
        /// <summary>
        /// Attempting a connection
        /// First will connect using TcpClient => Preventing bugs then transferring it to XSocket
        /// </summary>
        private async Task TryConnection()
        {
            try
            {
                var tcpClient = new TcpClient();
                await tcpClient.ConnectAsync("127.0.0.1", _port);

                if (tcpClient.Connected)
                {
                    _socket                        = new XSocket(tcpClient.Client);
                    _socket.OnReceive             += XSocketOnOnReceive;
                    _socket.ConnectionClosedEvent += SocketOnConnectionClosedEvent;
                    _socket.Read(true);
                    _socket.Write("sini|" + _client.CurrentUser.Id + "|" + _client.CurrentUser.Username + "#" +
                                  _client.CurrentUser.DiscriminatorValue);
                    _connectionFactor = true;
                }
            }
            catch (Exception)
            {
                _connectionFactor = false;
            }
        }