• Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection problem between client and server sockets  RSS feed

 
Luca Simonetto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, i have a little problem with my simple simple program. I'm at first year of university and I just started learning java and i tried to create a simple rock paper scissor program between a server program and a client one.
When I run them in my own network all is fine, i can play and score points, but when i try with a client that is on another network the pain starts
The problem is the usage of the program without being on the same network, the bypass of the firewall restrictions on incoming connections.
I thinked of using some port between the common ones, like the port 80, and if there isn't an apache server running it should work but in this case i don't know if i have to use some specific protocols like http...
If you can help me I would appreciate, i know i may portforward but i was thinking of a mobile program that can be portable
Here there is the code for the two programs
For Server


For Client


BTW I'm Italian so part of code is in my language
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First, it would help us if you tell us what the "pain" is. Second, it would also help us if you tell us what the network configuration looks like -- are you going on the LAN? going though a router to another LAN? through the internet? etc.

Henry
 
Luca Simonetto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
First, it would help us if you tell us what the "pain" is. Second, it would also help us if you tell us what the network configuration looks like -- are you going on the LAN? going though a router to another LAN? through the internet? etc.

Henry

the problem is the usage of the program without being on the same network, the bypass of the firewall restrictions on incoming connections. Inside the same LAN no problem, all works fine, when i try to use it over internet the client can't connect to server. I am trying to resolve without portforwarding, so the server program is portable without gaining access to every router's settings.
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luca Simonetto wrote:
the problem is the usage of the program without being on the same network, the bypass of the firewall restrictions on incoming connections. Inside the same LAN no problem, all works fine, when i try to use it over internet the client can't connect to server. I am trying to resolve without portforwarding, so the server program is portable without gaining access to every router's settings.



Not sure what you are asking of us. You can't break the rules of the router or firewall. They are setup that way for security reasons. If you can violate the rules programmatically, then your system administrator is not doing his/her job.

Unless you are referring to inconveniences (and not security violations), meaning you don't want to constantly pester your administrator to open ports. If so, I would ask your administrator if there is a UPnP setup/support. A UPnP supported router has a service that can automatically forward a port, from a range of pre-approved ports, to any machine in the LAN, via command, as needed. I have never used UPnP via Java, but I am sure there is a library for it somewhere.

Henry

 
Luca Simonetto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm ok i have also read of an intermediate server used as a bridge where client and server connect but is a solution too estreme for the use of the program.
I Will implement it for LAN only connections
 
Henry Wong
author
Sheriff
Posts: 22853
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luca Simonetto wrote:Hmm ok i have also read of an intermediate server used as a bridge where client and server connect but is a solution too estreme for the use of the program.
I Will implement it for LAN only connections


Actually, that is how lots of IM chat programs work. The clients will search for a UPnP service, in order to open the ports -- but if it fails (or doesn't work due to multiple routers), then it uses a public service.... This means that instead of having a program in a private network trying to access another program in another private network (which won't work without the ports forwarded); both clients connect to a public service instead.

And yes, you would need to write this service, and have it hosted on a machine that has direct access to the internet (or have the ports forwarded).

Henry
 
Luca Simonetto
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for helping me
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!