Skip to content

Instantly share code, notes, and snippets.

@frankbenoit
Created June 29, 2015 08:59
Show Gist options
  • Save frankbenoit/a168ee30eb831996b149 to your computer and use it in GitHub Desktop.
Save frankbenoit/a168ee30eb831996b149 to your computer and use it in GitHub Desktop.
package nbt;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
class Sender extends Thread {
public static void main(String[] args) throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.bind(new InetSocketAddress(15000));
ssc.configureBlocking(true);
SocketChannel ch = ssc.accept();
System.out.println("connection accepted");
// needed to trigger error
ch.socket().setTcpNoDelay(true);
ch.configureBlocking(true);
ByteBuffer buf = ByteBuffer.allocate(90);
buf.order(ByteOrder.BIG_ENDIAN);
int v = 1;
while( true ) {
buf.clear();
buf.putInt( v );
buf.position(0);
buf.limit(buf.capacity());
while( buf.hasRemaining() ) {
ch.write(buf);
}
Thread.sleep(2);
v++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment