Solved

Why does this Java network code work in my LAN, but not cross-campus?

Posted on 2015-02-19
44
107 Views
Last Modified: 2015-03-17
Hi
My java RTS game server works well with my client machine with 3 Java clients on my PC next to my Mac server, 1 foot away, with TCP messaging.

But, when I take my client class to my dad's office at the university, 4 miles away, the same code won't even make the initial TCP HELO message connection.
We initially had firewall issues, but the admin told us how to open the firewall.
What else could complicate initial TCP connections? There is no UDP, yet.

I currently run all the clients from the main() in my client class. It works fine at home.
But, the TCP isn't isn't making any long-distance connections.
Strange.
Any suggestions?

Thanks
0
Comment
Question by:beavoid
  • 20
  • 17
  • 6
44 Comments
 
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 40620613
Are you using port forwarding at either end? - Can you ping the host server from your Dad's machine?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40620920
I would add a Networking topic to this question. You're also not giving enough information, e.g.  what ports your software uses, etc.
0
 

Author Comment

by:beavoid
ID: 40623898
Sry!
I should have attached all my project code, I thought it might be a common issue...
Mods, Maybe you can also add the code zip below to the question text.

Okay.
The attached zip contains my complete Java project code of my RTS so far. It is a mutalisk moving party! Select a mutalisk and press 'M' to move-click it to a destination. Now, it has 10 mutalisks. If you change unitMax in both client and server if u like, there will be a different number. The mutalisk.gif is found on my web-space. No file needed. I haven't optimized it for 1000's of units yet.
Have all the server .java files on one machine and the client files on another machine for clean networking connectivity. You can init as many client windows as u like in the client main, just make sure the server is initialized with the same client count expected integer, in total. Maybe launching multiple clients from various locations would be good for a test? Change the server address variable in main as needed.

Enjoy. I haven't done any UDP, as I can't get the TCP to connect long distance.
Thanks
EEdeepRedNetworkingQuestionFeb22.zip
0
 
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 40623923
Still not convinced this is your code as much as it is you trying to play your LAN tested game over the Net.

Try setting up a VPN between the two machines and see if you get normal behaviour.  If you do then look more at your network routing than your code.

https://secure.logmein.com/products/hamachi/
0
 

Author Comment

by:beavoid
ID: 40623960
Thanks

It is confusing, why can't the packet be sent to the server socket? Is this a distance complication?
Does Blizzard do a Virtual Private Network for every Starcraft game?
I thought the whole point of TCP is that it is guaranteed delivery.
0
 
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 40623968
No, not distance.

No, but Blizzard expect every client to correctly identify its IP origin and port#.

Yes, that's what should happen but if your router or the router at your Dad's work aren't directing the packets appropriately then the two machines aren't talking to each other.  VPN isn't suggested as a solution, more a diagnostic.

Have a look though www.portforward.com to see what might be happening.
0
 

Author Comment

by:beavoid
ID: 40624049
Thanks
So, all my players will have this problem too? or is it just my server networking?
I cant expect my players to address something like this! - forwarding a port.

I only need to open a TCP Java stream between the two classes above on different machines, nothing for Xbox, PS2.
I am using a macbook. My dad is a PC. My server must forward a port?
Thanks
0
 

Author Comment

by:beavoid
ID: 40624053
Sorry, forwarding a port is done in code, not manually
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40624159
What you need to do (you should have it in your own mind for your own purposes anyway) is TELL us how your ports are meant to be configured, not expect us to pore through your code looking for how networking is used.

As a rule of thumb if there are ANY listening ports in your software then you can expect them NOT to hear anything from outside a LAN unless there is special configuration

Sorry, forwarding a port is done in code

How? That sounds unlikely unless you've managed to incorporate some clever UPNP code that you happen to be largely unaware of
0
 

Author Comment

by:beavoid
ID: 40625231
Thanks

My server socket is set up near the start of run()

clientJoiningSocket = new ServerSocket(SERVER_TCPport);

and the SERVER_TCPport is 1027

it then goes into an accept loop

what special configurations do computers playing blizzard games have? Are they set up in code, because it seems to just work on its own in Starcraft.
Thanks
0
 
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 40625265
Starcraft needs 6112 open - the Blizzard listen servers are in a DMZ but clients need to have uPNP enabled or set up port forwarding if they are using multiple devices behind their router
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40625269
IOW you  need to get your public facing router to forward requests to port 1027 to your server app box (or write UPnP code, as i said above)
0
 

Author Comment

by:beavoid
ID: 40625279
Thanks
Must I expect all my players to solve parts of this problem?
So, the university system ignored my packets?

The Blizzard listen servers are in a demilitarized zone. Would Starcraft even be playable at the university?
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40625392
I can't see (i'm guessing there's NO UPnP manipulation in your) code how it would work without problem in most situations since it requires a listening port to be forwarded to
0
 

Author Comment

by:beavoid
ID: 40629678
Is this a separate Thread that only listens on a port and transfers it to another? - forwards the packets? isn't that redundant?
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40630244
What is the 'this' you refer to?
0
 

Author Comment

by:beavoid
ID: 40630654
Thanks
By 'this', I mean what I must do to solve this one. Is this my fault :) ? I feel like the system is silly to bounce out valid outside communication.
If the VPN test works, then what?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40630702
A VPN is not a solution, or even part of a path to a solution  (unless i'm missing something)

Is this server (with its listening socket) the only server in one instance of a gaming session?
0
 
LVL 62

Accepted Solution

by:
☠ MASQ ☠ earned 167 total points
ID: 40630709
If this works over VPN then your code is fine for WAN gaming. Next you need to determine if your listen server is directly accessible from the Internet (either port-forwarding - which isn't ideal if you are looking at multiple connections - or the DMZ example of Blizzard). Hence the question about pinging the game server in my first response.

If the listen server is visible then you need to look at your client side connection.  With uPNP and a SoHo router a single player should be able to connect without any difficulty (slightly off-topic have you made plans for multiple players from the same location/router?).  The need for port-forwarding will be router dependent but changing those settings on a router you can control will further help in diagnosis.

[EDIT - the VPN suggestion is not proposed as a fix but to see if we can exclude local networking issues/prove what's going on]
0
 

Author Comment

by:beavoid
ID: 40633098
Hmm, will all my players have these issues to solve if a server gets hosted on their computers? or will solving the problem on my comp mean it works everywhere?
Servers can only exist in my DMZ?
Will do the VPN soon.
Thanks
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 333 total points
ID: 40633147
Almost certainly, yes. As i keep saying, ports don't get forwarded to the correct machine automatically. If they did, that would be a big security problem, wouldn't it?

The best way of solving this is by NOT requiring each game instance to have its own server
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:beavoid
ID: 40633257
But, now in RTS, each game must have its own server, to disallow cheating. - The game-state exists on the server, and clients are sent only valid vision.
That's what the game guru DPearson told me.
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40633363
Well you could have a master server that ALL game instances could connect through. This would mean EACH game instance would not need its own server (and most importantly, listening socket)
0
 

Author Comment

by:beavoid
ID: 40635055
I doubt my game will have thousands of world wide instances like Starcraft, so this is really a good suggestion. Do the individual server Threads then all exist on that machine? This is feasible.
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40635312
I'm not sure of your existing architecture so can't instruct on how to convert it. But the architecture i have in mind would be that the (single) server would essentially be a router for 'game packets'.

If you like, imagine a web server, which, on receipt of a request, did not return a response to the requester but to n other clients. This response would be an updated game state.
0
 

Author Comment

by:beavoid
ID: 40635780
Okay.

Thanks. I've just got to find a second in my dad's office since he is so defiantly busy. Actually, I'd like him to try and ping me from there. Do I need to have anything special open to receive the ping?
I just need to ask him to open a cmd console and ping my IP address?
What should he see, and why? Will anything help our diagnosis?
Can I ping him from my Macbook?
0
 

Author Comment

by:beavoid
ID: 40643318
CEHJ,
thanks
That's what I have, I just need to figure out why packets can't get to my dad's comp. I suspect it is the university security, and that my code is fine. So, it might not even be my fault. I might go and install the client on my mom's comp, because there is no security in between us.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40643447
That's what I have

What's what you have? You're saying you have one server for n game instances (that doesn't mean n clients of one game instance)?
0
 

Author Comment

by:beavoid
ID: 40648141
I have one server instance for a game, with n clients joining.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40648279
OK, so that means for every game, your network must support reaching that particular server.
0
 

Author Comment

by:beavoid
ID: 40652422
Yes. The UNCW firewall must be stopping me. I am going to my parents' house today, not too far away, where there are no firewalls, or issues to complicate client connectivity, to see if it runs smoothly. . . On bigger network. But, most importantly, to install Client on my Mom's Macbook, to test from bigger distance also.
Will the TCP IP packets reach the server at my home from their house without issue?
I fire UDP backup duplicate packets behind the TCP to try and ensure delivery, quicker.
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40652478
Will the TCP IP packets reach the server at my home from their house without issue?
Impossible to say without knowing anything about your network. At a guess, unless you configure your router as i've outlined above - no.
0
 

Author Comment

by:beavoid
ID: 40656809
I tried it, and a client on my mother's Macbook can't connect with a server on my Macbook at my house.
Why are routers past of this discussion? It again leads me to suspect that you're implying that the solution is hardware setup? Starcraft and Age of Empires don't have that type of problem. I don't have to configure my network for any games. Will my players also have to?
Thanks

I was taught that the whole point of TCP was guaranteed delivery!
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 333 total points
ID: 40656876
It again leads me to suspect that you're implying that the solution is hardware setup?
I'm not implying anything. I've stated several times that ordinarily packets will not be routed into your LAN from the Internet. Routers will not allow it without special configuration

I was taught that the whole point of TCP was guaranteed delivery!
So, if i know the address of the Pentagon you think we should be allowed to make an arbitrary TCP/IP connection to a machine on their LAN?
0
 

Author Comment

by:beavoid
ID: 40657049
Good points. Thanks


Apologies. I think I needed to see it fail.

What if Jack Ryan was to take Kim Jong Un out at Starcraft From the Pentagon, Or Elf Bowling?


 So my router isn't accepting incoming connections. No project of mine can keep a server here until I change the router. My mother's router obviously has the same routing issue. Will changing this security open my and her system to e-vandalism?

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40657121
It's not just a security issue. Your router isn't smart enough to know which services are running on which host on the LAN anyway. But yes, notionally, the more ingress you allow into your LAN, the more susceptible you are to attack.

The moral of the story is that you need to get to know your router and how it's configured
0
 

Author Comment

by:beavoid
ID: 40657867
Thx
So, Linksys's docs have a page devoted to web-based router setup.  here
I can get to the DMZ options in Applications and Gaming.

If I enable it (the DMZ) , - is it safe? - Will the last byte of the IP Address I enter spring to life as my DMZ address? Is that what I need?
And I must disable it afterwards to stop hooligans and malicious entities from violating my comp?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40658260
That doesn't look like the right page. You should get the full manual for your router. But you don't necessarily have to set up a DMZ.

You do have to set up Dynamic DNS though (as i mentioned earlier), as clients won't know if/when your router's IP address changes
0
 

Author Comment

by:beavoid
ID: 40662425
Thanks
I think I remember the Linksys manual. It seemed grounded only in getting the setup done for regular household use?
How would a dynamic DNS be of significant use, since my router still won't allow incoming TCP packets.

Until I set up the dynamic DNS, I can code it with the one server IP address?
0
 
LVL 62

Expert Comment

by:☠ MASQ ☠
ID: 40663387
Which model router are you using?  
Have you looked it up on the Portforward site?
Does your server have a fixed IP address on your network?

There's a difference between not allowing incoming TCP packets and not being able to direct them appropriately.

Is your "server" wired to the router and the router wired to your ISP?

Who is your ISP?  

Do you have fixed IP address with them? Depending on the type of account you have some ISPs will block this kind of traffic anyway.  Verizon's basic accounts block their customers hosting games servers on their lower cost accounts (although normally just on the commonest ports).
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40663404
think I remember the Linksys manual.
Don't remember it. Download it and read it. There'll be only the one full manual

How would a dynamic DNS be of significant use, since my router still won't allow incoming TCP packets.
They've got to reach your router. How are they going to do that it you're not 100% sure of its address?

Until I set up the dynamic DNS, I can code it with the one server IP address?
Yes, but your code will break when the IP address changes
0
 

Author Comment

by:beavoid
ID: 40663744
Thanks
Yes, someone warned me of hoping my LAN tested game would work on the Internet.

I have a Linksys Wireless_G broadband WRK346

My IPAddress always starts with a.b  then x.y and y is  usually 100,101, 102 or 110.   x  is always 1
It always works inside my LAN. What do u suspect in that manual might solve this issue?

Is this not a frequent problem to solve?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40664181
What do u suspect in that manual might solve this issue?
That's the wrong question. The fact that you're asking it suggests that you still don't understand the causes. I'd advise you to re-read my comments, as i'm not going to continue repeating myself
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now