Created
July 17, 2015 01:16
-
-
Save csm/a574316637162c7336ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.*; | |
import java.net.*; | |
public class NetTest { | |
public static void main(String[] argv) throws Throwable { | |
Socket socket = new Socket(); | |
try { | |
System.out.println("connecting socket..."); | |
socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 31337)); | |
socket.connect(new InetSocketAddress(InetAddress.getByName(argv[0]), 4242)); | |
System.out.printf("have socket; connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown()); | |
OutputStream outStream = socket.getOutputStream(); | |
OutputStreamWriter outWriter = new OutputStreamWriter(outStream); | |
System.out.printf("emitting test event...%n"); | |
outWriter.write("put test.sample.event " + System.currentTimeMillis() + " 0.0 when=before\n"); | |
outWriter.flush(); | |
System.out.printf("sleeping for > 60s... connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown()); | |
Thread.sleep(120 * 1000 + 500); | |
System.out.printf("slept, emitting test event... connected? %s closed? %s outputShutdown? %s inputShutdown? %s%n", socket.isConnected(), socket.isClosed(), socket.isOutputShutdown(), socket.isInputShutdown()); | |
outWriter.write("put test.sample.event " + System.currentTimeMillis() + " 0.0 when=after\n"); | |
outWriter.flush(); | |
} catch (Exception x) { | |
System.out.println("caught exception!"); | |
x.printStackTrace(System.out); | |
} finally { | |
System.out.println("closing socket"); | |
socket.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What dafuq is wrong with AWS ELBs?
If you connect the above to an ELB with a 60 second idle timeout, the socket will go to
CLOSE_WAIT
state, but the socket doesn't appear closed from the write side, and the write is still accepted. Oh, but the data written is dropped on the floor, and never makes it to the other side.And. And! If you
close
the socket, the socket hangs around inLAST_ACK
for a minute or so. Thanks Amazon!