Ejemplo n.º 1
0
    //---------------------------------------------------------------------
    public void connect(string ip, int port)
    {
        mIp   = ip;
        mPort = port;

        EndPoint server_address = new IPEndPoint(IPAddress.Parse(mIp), mPort);

        mSession = new TcpClientSession(server_address);
        mSession.DataReceived += _onReceive;
        mSession.Connected    += _onConnected;
        mSession.Closed       += _onClosed;
        mSession.Error        += _onError;

        mSession.connect();
    }
Ejemplo n.º 2
0
    //---------------------------------------------------------------------
    public void connect(string ip_or_host, int port)
    {
        mIpOrHost = ip_or_host;
        mPort     = port;

        IPAddress ip_address = null;
        bool      is_host    = !IPAddress.TryParse(mIpOrHost, out ip_address);

        IPHostEntry host_info = null;

        if (is_host)
        {
            host_info = Dns.GetHostEntry(mIpOrHost);
        }
        else
        {
            host_info = Dns.GetHostEntry(ip_address);
        }

        IPAddress[] ary_IP = host_info.AddressList;

        if (is_host)
        {
            mSession = new TcpClientSession(mIpOrHost, mPort);
        }
        else
        {
            EndPoint server_address = new IPEndPoint(IPAddress.Parse(mIpOrHost), mPort);
            mSession = new TcpClientSession(server_address);
        }

        mSession.DataReceived += _onReceive;
        mSession.Connected    += _onConnected;
        mSession.Closed       += _onClosed;
        mSession.Error        += _onError;

        mSession.connect(ary_IP, is_host);
    }