Exemple #1
0
        public Client(TcpClient client, IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod, ClientConnectedHandler onConnect = null)
        {
            _client = client;
            Connected = true;
            _client.NoDelay = true;
            _eventDispatcher = eventDispatcher;
            _parseMethod = parseMethod;
            _networkInfos = _client.Client.RemoteEndPoint.ToString();

            if (onConnect != null)
                onConnect.BeginInvoke(this, null, null);

            new Task(Receive).Start();
        }
Exemple #2
0
        public Client(string ip, int port, IEventDispatcher eventDispatcher, Parser.ParserMethod parseMethod, ClientConnectedHandler onConnect = null)
        {
            try
            {
                _client = new TcpClient(ip, port);

                Connected = true;
                _client.NoDelay = true;
                _eventDispatcher = eventDispatcher;
                _parseMethod = parseMethod;
                _networkInfos = _client.Client.RemoteEndPoint.ToString();

                if (onConnect != null)
                    onConnect.BeginInvoke(this, null, null);

                new Task(Receive).Start();
            }
            catch (SocketException se)
            {
                Connected = false;
            }
        }