//********* Blocking client *************************************** import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.net.InetSocketAddress; public class BC { // BlockingClient public static void main(String[ ] args) throws Exception { if (args.length < 1) { System.err.println("Usage: BC "); return; } // Create a ByteBuffer to receive data. ByteBuffer buff = ByteBuffer.allocate(buff_size); // Open a socket channel and configure it as blocking. SocketChannel sc = SocketChannel.open(); sc.configureBlocking(true); // Attempt to connect: as blocking is on, the call // blocks until successful or an exception is thrown. sc.connect(new InetSocketAddress(args[0], port)); sc.read(buff); // also blocks until data are available sc.close(); System.out.println(new String(buff.array())); } private static final int port = 2233; private static final int buff_size = 512; // in bytes }