Code example for SocketChannel

Methods: close, isOpen

0
		try { 
			mSocketChannel = SocketChannel.open();
			// set nonblocking mode 
			mSocketChannel.configureBlocking(false);
 
			// connect to relay borad 
			InetSocketAddress inet_addr = new InetSocketAddress(
					RELAY_BORAD_HOST, RELAY_BORAD_PORT);
			if (mSocketChannel.connect(inet_addr)) {
				// void 
			} else { 
				for (int i = 0; i < 5; i++) {
					if (mSocketChannel.finishConnect()) {
						break; 
					} else { 
						Log.v("relayService",
								"sleep 500ms wait for connect complete"); 
						try { 
							Thread.sleep(500);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block