简体   繁体   中英

Java socket not connecting on some computers

I've been making a java SE application on another computer for couple of months with Netbeans. The application uses Javas sockets and connects to another application to the another computer (or to the same) through port 4444. The application connects on the first computer perfectly to another application: runned from netbeans, runned from command line and runned from a jar file.

Now I'm continuing the project on another computer. At first I tried to run the same source on this computers Netbeans debugger. Application starts, and it connects to another application, but it stops immediately. No error messages or exceptions. The screen doesn't freeze, but neither won't the applications start to communicate with each other.

I also tried to run the applications jar file from the command line. The same problem appears. It makes connection to another app, but nothing else happens.

Finally started the application from the jar file by doubleclicking it. Now it makes a connection and starts to communicate with another.

Firewall isn't blocking the application or netbeans. I've also tried to run netbeans with firewall down, but still no results. Java has been updated on both computers. For some reasons the application runs perfectly on some computers, and on others, it does this annoying thing.

It's possible that port 4444 is used by another application.

Check this by using the netstat utility.

Your application should be configurable. IE port 4444 shouldn't be hard coded.

Grab a stack trace from the running application. It will tell you where the program is "stuck".

You may also benefit from adding logging to your app. This will drop statements to a file or system out/err that you can use to identify its internal state. For example; when you write to a socket:

OutputStream os = socket.getOutputStream();
while (true) {
    System.out.println("write loop:enter");
    os.write("machine 1".getBytes());
    System.out.println("write loop:exit");
}

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM