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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s