isConnected() публичный Метод

public isConnected ( ) : bool
Результат bool
Пример #1
0
        public bool connect(string hostname, int port)
        {
            if (sockChan == null)
            {
                sockChan = new SocketChannel();
            }
            else if (sockChan.isConnected())
            {
                disconnect();
            }
            sockChan.connect(hostname, port);

            return(sockChan.isConnected());
        }
Пример #2
0
        public bool isConnected()
        {
            bool conn = false;

            if (activeConnection && sockChan != null && sockChan.isConnected())
            {
                // try to read 1 byte, if this fails then the socket was reset
                int nread = -1;
                try {
                    ByteBuffer tmp = ByteBuffer.allocate(1);
                    sockChan.socket().Client.Blocking = false;
                    nread = sockChan.read(tmp);    // fast non-blocking read
                    sockChan.socket().Client.Blocking = true;
                } catch (IOException e) { }
                //System.Console.WriteLine("read " + nread + "bytes"); System.out.flush();
                if (nread < 0)
                {
                    activeConnection = false;
                }
                else
                {
                    conn = true;
                }
            }
            return(conn);
        }
Пример #3
0
        public bool connect(string host, int port)
        {
            if (sockChan == null)
            {
                sockChan = new SocketChannel();
            }
            else if (sockChan.isConnected())
            {
                disconnect();
                sockChan = new SocketChannel();                 // force build of new socket connection
            }
            this.host = host;
            this.port = port;
            sockChan.connect(this.host, this.port);

            return(sockChan.isConnected());
        }
Пример #4
0
 virtual public bool connect(string hostname, int port)
 {
     // if ( sockChan == null )
     //  {
     sockChan = new SocketChannel();
     // }
     // else if ( sockChan != null && sockChan.isConnected()) {
     //	disconnect(); // disconnect old connection
     //}
     sockChan.connect(hostname, port);
     activeConnection = sockChan.isConnected();
     if (activeConnection)         // cache the connection info
     {
         this.host = hostname;
         this.port = port;
     }
     return(activeConnection);
 }