Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Fixed] Need Help with Server/Client Connections (Connecting over Internet)  (Read 547 times)
0 Members and 1 Guest are viewing this topic.
Offline RyanMB97

Junior Devvie

Medals: 1
Projects: 1

« Posted 2013-05-26 15:27:16 »

Hello! I've recently been looking into clients and the like, and was trying to test it out with one of my friends over the internet (Because it tested fine over localhost). The weird thing is that crashes whenever he goes to enter the IP to connect to (Mine). It listens on port 7777, and here's the code. I have the server and client separate, so they have different github URLs. Here they are:


According to the error message my friend sent me, it was somehow related to line 21 in Client, where I create the Socket. Any and all help is appreciated, and thanked in advance!

-Ryan Mitrun

P.S. Close-Up of problem line(s):
System.out.print("Enter the IP of the server you are connecting to: "); // Ask for the IP
String socketInput = input.nextLine(); // Set the socket IP to whatever they set

System.out.println("Connecting..."); // Connecting to server
socket = new Socket(socketInput, 7777); // Create a socket, connected to the server

P.P.S. The issue was port-forwarding. I just adjusted my router accordingly. Thanks for the help and suggestions anyways!
Offline deathpat
« Reply #1 - Posted 2013-05-26 16:51:09 »


do you have a stack trace of the error or something similar ?

If your code works in local but not over internet, there are good chances that the guilty is your network configuration. Are you launching your server behind a router ? If yes have you forwarded the ports you're listening to ?

work in progress : D A E D A L U S
Offline RyanMB97

Junior Devvie

Medals: 1
Projects: 1

« Reply #2 - Posted 2013-05-26 17:12:25 »

I haven't tried forwarding the port, but I'll definitely try that next. Already tested via normal internet connections, and Hamachi (Internet-based LAN), so that might be the issue. Here's the stack-trace:
Exception in thread "main" Connection timed out: connect
at Method)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at<init>(Unknown Source)
at<init>(Unknown Source)
at Client.handShake(
at Client.main(

Again, the problem line is 21. I have no idea what the rest means other that that it has something to do with the socket (Obviously). I'll try forwarding the port and see if that works. In the mean-time, any other suggestions are appreciated!

-Ryan Mitrun

Modification 1: Not sure what you mean about hosting behind a router, but I'm just running it as an Executable Jar via a Batch file.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Man
« Reply #3 - Posted 2013-05-26 17:15:54 »

Based on this I'd be willing to bet it's a firewall problem, so definitely try forwarding the port. I've had similar problems when writing networking code. Works great over LAN but as soon as I send it to someone to test, one of our firewalls or routers blocks the port and it won't work.
Offline deathpat
« Reply #4 - Posted 2013-05-26 17:44:30 »

ok from your answer I'm 99% sure it's a routing issue Smiley

Basically if you have an internet box and you are able to connect several network devices on it without issues, then your internet box certainly acts as a router. You should check wikipedia or google to learn a bit about it.

In a few words, in the case of a home internet connection, the router is there to dispatch packets to the appropriate computer/device connected to it. From the outside of your home you have only one visible IP address: the one of your internet box. If from your computer you connect to a website, when the website returns packets to you, it's the router's job to forward these packets back to your computer and not to the other devices ( mobile phone, tablet ... ) that is also connected to internet.
When the request is initiated from you the router is able to identify the packets coming back and forward them to you ... but when the request is initiated from outside your home, the router has no way to know if the packet should go to your computer, your mobile or your tablet.
That's why you need to forward ports: you configure the router for it to know that if it gets a connection on port 7777, then it should forward the packet to your computer ( identified by your IP address ). It's that simple.

Also to do this you have to be sure that your computer has always the same IP address in your local home network. If you get an IP address automatically ( via DHCP ), there's a good chance that your internet box acts also as a DHCP server. In this case you should configure it as well to always return the same IP address to you ( for your MAC address ).

Hope this helps Wink

work in progress : D A E D A L U S
Offline RyanMB97

Junior Devvie

Medals: 1
Projects: 1

« Reply #5 - Posted 2013-05-26 17:52:24 »

I fixed it. Turned out that it was indeed a routing issue. I had my same friend I was trying to connect to fix it. Also, as you suggested deathpat, I also got a static IP while I was at it. Thanks for the help and everything! Much appreciated.

Very Much Thankful,
-Ryan Mitrun

P.S. I'll certainly look into it, death. Thanks for the info!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (11 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (17 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (29 views)
2015-07-25 00:14:37

BurntPizza (40 views)
2015-07-24 22:06:39

BurntPizza (24 views)
2015-07-24 06:06:53

NoxInc (27 views)
2015-07-22 22:16:53

NoxInc (18 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!