-1

I start SqlServer Express that works on port 1433. Then I run a Java application that creates a server socket that executes a bind to the local ip and port 1433. I do not understand why it does not give an execution error. Can there be two applications working on the same port?

This is the java code:

public static void main(String[] args) throws IOException {
    ServerSocket sSocket = new ServerSocket();
    sSocket.bind(new InetSocketAddress("192.168.0.13", 1433));
}

Thank you

Alberto
  • 305
  • 3
  • 11

1 Answers1

-1

Your operating system handles the sockets and knows if it was set for internal use with the IP 127.0.0.1 or external use with 192.168.0.13. A double binding of one socket with the same IP and Port is not possible. A 0.0.0.0 IP will listen to all sources internal or external (all IP'S) on a given port.

P.S. Try to use new Socket(IP, PORT).

  • No. Explicitly binding to the external interface, does not bind to localhost. – Thorbjørn Ravn Andersen Feb 14 '18 at 21:17
  • sry, I wasn't precise enough and changed it. – Alexander M. Feb 14 '18 at 21:21
  • Sorry, but I don't understand it. I've changed the ip to 0.0.0.0 to listen all the interfaces but it works...with sql server express running. Could be Sql server listening other port? How can I now it? – Alberto Feb 14 '18 at 21:26
  • First go to your Task Manager and search for the Process ID (PID) of your SQL server in the details tab. if you are on windows go to console and type: netstat -aon here you can find all bound sockets and there PID's – Alexander M. Feb 14 '18 at 21:32
  • What on earth does your PS mean? An `InetSocketAddress` isn't a binding at all, let alone an external binding, and `Sockets` don't 'bind to all'. – user207421 Feb 14 '18 at 21:38