Exemplo n.º 1
0
        protected virtual void OnAcceptConnection(Socket socket)
        {
            var xSocket = new XSocket(socket);

            _clientsConnected.Add(xSocket);
            OnAccept?.Invoke(this, new XSocketArgs(xSocket));
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 3
0
 public XSocketArgs(XSocket xSocket)
 {
     XSocket = xSocket;
 }