Jump to content
  • Advertisement
Sign in to follow this  
basvanmeurs

Binding on a port works for some apps, but not for Java apps

This topic is 3580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a strange problem. It could be Java-related, but it could be something I am missing. I have a server application, written in Java using ServerSocket. It just waits for new connections and then prints a message. It waits on port 20472. It works fine locally. My PC is behind a router/firewall (SpeedTouch 780). So I forwarded 20472 to my computer. I tested the port using uTorrent and it is perfectly connectable. I also used http://www.canyouseeme.org/ to double check. In the router logs I see that the port is being properly forwarded and connections are handled by uTorrent as they are supposed to:
Info 	00:02:06 (since last boot)	FIREWALL event (1 of 28): created rules


Info 	00:02:04 (since last boot)	UPnP action 'AddPortMapping' from ip=192.168.1.70 (Success)


Info 	00:02:04 (since last boot)	UPnP action 'AddPortMapping' from ip=192.168.1.70 (Success)


Info 	00:01:01 (since last boot)	UPnP action 'DeletePortMapping' from ip=192.168.1.70 (Success)


Info 	00:01:01 (since last boot)	UPnP action 'AddPortMapping' from ip=192.168.1.70 (Success)
and after that connections are handled appriopriately:
Info 	00:02:06 (since last boot)	FIREWALL rule (1 of 1) : Protocol: TCP Src ip: 77.165.80.136 Src port: 49275 Dst ip: 192.168.1.70 Dst port: 20472 Chain: forward_host_service Rule Id: 1 Action: accept
Now I close uTorrent and wait for 15 minutes. After a while, I see the following message appearing in the router logs:
00:04:06 (since last boot)	FIREWALL event (1 of 1): deleted rules
Maybe I get something wrong but why should the firewall add and delete rules dynamically when I already set the forwarding manually? Is this normal behaviour for routers? If it works I'm fine with it. But unfortunately, it doesn't for Java applications! Because when I start the java app, I don't see the 'add rules' message that I do see when I start uTorrent. When the server starts listening on 20472, I get no Exception and local calls over localhost have the desired effect, so it should be fine. But, probably because the rules had not been added to the router, external calls to the port (tested using http://www.canyouseeme.org/) get a time out! Nothing happens, and I don't even see any appearing message in the logs. The calls are simply blocked by the firewall and not forwarded to my PC. A clue: When I first start uTorrent, then close it, the Java application works for external calls until the 'delete rules' message appears. From then it will not accept new connections, even if you restart. I suspect that the cause is these router rules, that are not created when starting a java application for some reason. I tried this in WinXP, and in Linux (I have dual-boot), and the exact same problem appeared on both OSes. So from this I conclude it's unlikely to have anything to do with OS or configuration settings. Has it to do with Java? Or with the router? I am completely clueless and would like a solution or an explanation, or at least hear from people with the same problem. Or at least answer the question whether it is normal for a router to work with dynamic rules which are created and removed in run-time? Any information would be welcome! Thanks in advance for your help.. Bas

Share this post


Link to post
Share on other sites
Advertisement
It looks like uTorrent is using uPnP with a uPnP-enabled "router". Your Java application isn't using uPnP, and thus can't tell the router how to forward packets.

Why the router doesn't care for your static configuration isn't something I can help you with though.

Share this post


Link to post
Share on other sites
Thanks your help, that explains a lot! I'm going to try to find out if, and how I can set the router to work statically instead of using uPnP.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!