LanguagesNamedAfterCofee
LanguagesNamedAfterCofee

Reputation: 5952

Java program blocking ports?

There is a program called PC^2 (a programming contest judging system). You can submit java files to it, and it will compile/run it.

I have a program that creates a socket, when I submit this to PC^2 it runs it fine, but I can't access the url (http://ip:port/) on my web browser. But when I quit PC^2 (my program is still running) it works when I hit refresh on my web browser. This means that PC^2 is somehow blocking the port, but not occupying it (i.e. making it's own ServerSocket that occupies the port) because if it was occupying it, then my program would have thrown an exception and quit.

What are possible ways that a Java program can do this? And since PC^2 is closed source, I can't look there.

Upvotes: 0

Views: 192

Answers (2)

Fuhrmanator
Fuhrmanator

Reputation: 12882

If PS^2 is running locally, you could check to see if it's listening before you run your program. I saw PS2 Version 9 uses sockets for communication, so perhaps that's what's going on? In Windows, these instructions will help confirm which process is listening on the ports. In linux, this page will help.

Upvotes: 1

stefan bachert
stefan bachert

Reputation: 9608

Only one program at a time could listen to a certain port.

Same happens if you start tomcat twice using the some port

This has nothing to do with java. That is how sockets work

Upvotes: 3

Related Questions