code

code

kundas
System.out.println("thread G is starting...");

SocketChannel channel = SocketChannel.open();
InetSocketAddress isa = new InetSocketAddress("localhost", 8080);
channel.connect(isa);
channel.configureBlocking(false);

while (true) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    /*int bytesRead = channel.read(buf);
    if (bytesRead == -1) {
        System.out.println("no int has been read");
        continue;
    }

    int in = buf.getInt();*/

    /*Random random = new Random();
    int p = random.nextInt(5);
    try {
        Thread.sleep(p);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }*/

    Scanner scanner = new Scanner(System.in);
    //System.out.println("enter integer:");
    int in = 13;
    //scanner.nextInt();

    int out = in * in * in;

    buf.clear();
    buf.putInt(out);
    buf.flip();

    while (buf.hasRemaining()) {
        channel.write(buf);
    }
    break;
}

channel.close();


Report Page