Skip to content

Instantly share code, notes, and snippets.

@alexkasko
Created February 10, 2013 14:43
Show Gist options
  • Save alexkasko/4749782 to your computer and use it in GitHub Desktop.
Save alexkasko/4749782 to your computer and use it in GitHub Desktop.
@Test
public void testTcp() throws InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
try {
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress(2121));
Socket client = ss.accept();
byte[] data = new byte[200];
fill(data, (byte) 42);
OutputStream os = client.getOutputStream();
for (int i = 0; i < 100000; i++) {
os.write(data);
Thread.sleep(3000);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
Socket so = new Socket("127.0.0.1", 2121);
byte[] data = new byte[300];
InputStream is = so.getInputStream();
for(;;) {
long start = System.currentTimeMillis();
int count = is.read(data, 0, data.length);
long wait = System.currentTimeMillis() - start;
System.out.println("Bytes read: [" + count + "], wait time: [" + wait + "]");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
Thread.sleep(100000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment