Code example for SocketChannel

Methods: socket

0
	 
	/** 
	 * Server handle new client coming in. 
	 */ 
	public void onNewClient(SocketChannel schannel){
		String ipaddr = schannel.socket().getInetAddress().getHostAddress();
		Log.d(TAG, "onNewClient : server added remote client: " + ipaddr);
		mClientChannels.put(ipaddr, schannel);
	} 
	 
	/** 
	 * Client's connect to server success,  
	 */ 
	public void onFinishConnect(SocketChannel schannel){
		String clientaddr = schannel.socket().getLocalAddress().getHostAddress();
		String serveraddr = schannel.socket().getInetAddress().getHostAddress();
		Log.d(TAG, "onFinishConnect : client connect to server succeed : " + clientaddr + " -> " + serveraddr);
		mClientSocketChannel = schannel;
		mClientAddr = clientaddr;
		((WiFiDirectApp)mService.getApplication()).setMyAddr(mClientAddr);
	}