Hi all, I have a question about SpiderMonkey. Is it normal that even if I declared a TCP/UDP port to use by the server and client, it switches back to another port? I have also noticed that the port increases on each application execution, probably meaning it’s not closed gracefully upon exit.
I’m asking because as it sits now, it’s nearly impossible to predict what port SpikerMonkey will use upon a client connection and so how am I supposed to forward the port on my router if it keeps changing randomly like this?
I’ve set up my SpikerMonkey server app like this:
[java]
this.server = Network.createServer(51010);
this.server.addConnectionListener(sl);
this.server.addMessageListener(sl);
this.server.start();
[/java]
… and my client app is launching like this where server_ip is like 123.123.123.123:
[java]
this.client = Network.connectToServer(server_ip, 51010);
this.client.addClientStateListener(cl);
this.client.addMessageListener(cl);
this.client.start();
[/java]
Everything works well on localhost, because I do not have any ports to forward on my router, so even if it changes port randomly, they’re all available and open locally… but on external IP, that’s where I’m kind of lost.
If I println() new client connections on the server using this:
[java]
System.out.println("SERVER connection ESTABLISHED: " + conn.getAddress());
[/java]
I’m getting this: SERVER connection ESTABLISHED: /127.0.0.1:49303
…and then the second time I launch my app, I’m getting this: SERVER connection ESTABLISHED: /127.0.0.1:49426
…and then the third time I launch my app, I’m getting this: SERVER connection ESTABLISHED: /127.0.0.1:49430
As you can see, it’s incrementing over time, even like when my app is not launched, just letting my computer idle for a couple minutes, the increment will be bigger, but it’s always changing ports. I’ve never actually seen my SpiderMonkey app use port 51010 like I defined it. I tried defining it to a different port like 59873 just to be sure it wasn’t randomly in use, but it’s still going with 49xxx and incrementing.
Anybody has any ideas of what could cause this and how to force SpiderMonkey to use the port I defined in the code?
Thx