~/ learn/ comp-348/ cards/ Constructing, connecting, and interrogating a socket
1 of 4

Connect with a deadline, then read the endpoints the OS actually assigned.

Connect with a deadline, then read the endpoints the OS actually assigned.

Answer

Socket socket = new Socket(); socket.connect(new InetSocketAddress("dict.org", 2628), 5_000); socket.setSoTimeout(10_000); System.out.println(socket.getRemoteSocketAddress() + " from local port " + socket.getLocalPort());

Line 2 bounds the handshake at five seconds; line 3 bounds every later read at ten. The remote endpoint is what you asked for, the local port is ephemeral and different on every run.

Harold 4e ch8 §Constructing and Connecting Sockets; §Getting Information About a Socket

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/8bf1f006-eccc-40f3-8018-4c22af044adc/flashcard utf-8 LF