This is my first question here, I'm going to try and give as much info as I can.
I have a local installation of Apache 2.2 installed on my PC. I have it default to bind to port 100 (Don't ask me why). When I run Apache, I cannot create a socket server with port of 100 because this port is already in use. What I want to do is duplicate this functionality in a Java Server I'm writing.
Currently, I create a socket server like this:
ServerSocket srv = new ServerSocket(100);
The problem is, this doesn't block other applications from using this port. I can run more then one copy of my Java application, or even start my Apache server after this. I want the java Server Socket to mimic the behaviour of Apache and block other applications from binding to the chosen port.
I tried using Google, and the only thing I could find was this http://www.dreamincode.net/forums/topic/124376-block-port/ which implies that creating a socket server as shown above should block the port from use in other applications.
I'm using Windows 7 Ultimate-64bit, NetBeans IDE 6.9.1, and Java 1.6.0_23.
Thanks user658991,
It appears that the port will not be blocked until after a client connects or unless I call ServerSocket.accept();
try
{
ServerSocket server = new ServerSocket(12345);
System.out.println("Socket Server Established on port " + server.getLocalPort());
server.accept(); // Code Stops here until connection is completed.
// Do Stuff
}
catch(IOException e)
{
System.out.println("Socket Server Connection Failed!");
System.out.println(e);
System.exit(-1);
}