Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 364 times)
0 Members and 1 Guest are viewing this topic.
Offline RyanMB97

Junior Member


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:

Server: https://github.com/RyanMB97/ServerStuff/
Client: https://github.com/RyanMB97/ClientStuff

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!

Thankfully,
-Ryan Mitrun

P.S. Close-Up of problem line(s):
1  
2  
3  
4  
5  
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 »

Hi,

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 Member


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:
Quote
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.connect0(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.Connect(Unknown Source)
at java.net.Socket.Connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at Client.handShake(Client.java:21)
at Client.main(Client.java:40)

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!

Thankfully,
-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 Member


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!