Created
February 10, 2013 14:43
-
-
Save alexkasko/4749782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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