ipaq Socket problems
843849Nov 28 2001 — edited Dec 5 2001I'm running into the following problem while running a PersonalJava application on a Compaq ipaq 3600. The Java application tries to open a Socket connection to a server, then close the connection for a number of iterations
(currently 300). However, when it reaches the iteration in the range of approximately 193-199, it throws a java.net.ConnectionException when it tries to create a new Socket. I am unable to get any Java application
to create a new Socket after this happens, until I perform a soft reset of the ipaq. This happens every time I run the application. The server I'm currently connecting to is an apache webserver, but I have tried to connect to various servers (different host/port combinations) and the problem always occurs.
It is occurring on both the Jeode and Sun WinCE PersonalJava beta 1.1 implementation.
The following source code produces the problem:
import java.io.*;
import java.net.*;
public class SocketTest {
public static void main(String args[]) {
Socket s1 = null;
PrintWriter pw = null;
try {
FileOutputStream fos = new FileOutputStream("\\socketoutput.txt");
pw = new PrintWriter(fos, true);
} catch (IOException ioe) {
System.exit(0);
}
try {
for (int i = 1; i < 300; i++) {
s1 = new Socket("192.168.0.57", 80);
pw.println("Opened socket " + i);
pw.println("socket is " + s1.toString());
s1.close();
pw.println("closed socket " + i);
try {
Thread.sleep(600);
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace(pw);
if (s1 != null) {
pw.println("Socket.toString(): " + s1.toString());
}
pw.println("Exception message: " + e.getMessage());
pw.close();
}
System.out.println("At end");
}
}
(Apologies for the indentation not appearing in the above code)
The exception that is thrown when the Socket cannot be created is:
java.net.ConnectException
at java.net.PlainSocketImpl.connect (Native Method)
at java.net.PlainSocketImpl.connect (bytecode 33)
at java.net.PlainSocketImpl.connect (bytecode 9)
at java.net.Socket.<init> (bytecode 96)
at java.net.Socket.<init> (bytecode 9)
at SocketTest.main (bytecode 15)
Socket.toString(): Socket[addr=192.168.0.57/192.168.0.57,port=80,localport=1607]
Exception message: null
Has anyone else see anything like this? If so, is there a workaround? This is only a test application, the real-life application will involve a number of socket open/close operations during its lifetime, but this problem keeps occurring.
Any help would be appreciated.
thanks,
Derek