Socket problem observations

In my previous post I reported that I had problem with FitNesse to open a socket. I made further observations. This is no problem with FitNesse itself, it seems to be more general. I looked at the FitNesse sources and extracted this small test class reproducing my problem:

package playground;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

public class SocketTest {
public static void main(String[] args) throws IOException {
Socket socket = new Socket();
SocketAddress localaddress = new
InetSocketAddress(InetAddress.getLocalHost(),8888) ;
socket.bind(localaddress);
System.out.println(“Socket established #1”);
socket.close();

socket = new Socket(java.net.InetAddress.getLocalHost().getHostName(), 8888);
System.out.println(“Socket established #2”);
socket.close();
}
}

Of course I expect that I get both System outs, but for some reason the first succeeds, the second rans into a timeout.

java -cp bin playground.SocketTest
Socket established #1
Exception in thread “main” java.net.ConnectException: Operation timed out

What I have recognized in the meanwhile is that it has something to do with my UMTS modem connection. When I am online I sometimes (!) run into this problem, but when I disconnect then it succeeds.

Leave a comment