Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (483)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
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  
  How do you configure a router with Java to make it...  (Read 942 times)
0 Members and 1 Guest are viewing this topic.
Offline Anju_Maaka

Senior Newbie


Exp: 2 years



« Posted 2014-03-29 17:21:48 »

I have started working with making a game meant to be played by several persons across the web.
I have it working and all, you can open it and play in a LAN but I have a problem. When I want to connect to another computer through the internet, not a LAN, the NAT in the router gets in the way (of course, it doesn't know that an incomming call is for my computer and not my brother's).
So, I know there are ways to configure a router, from your computer, so that it sends all calls to a certain Port to the same computer in the house. What I'm wondering is if there is a way to do this with Java and in that case I'd love to see some code with a function that takes an Integer (a port number) and makes the router send all received messages with that destination port to the computer that used this function. That way I'll be able to set up a connection and let the game clients communicate with each other.

I hope this wasn't confusing, I don't know how to write it better I'm afraid.
Offline saucymeatman
« Reply #1 - Posted 2014-03-29 17:59:14 »

I dont know why you'd have to configure your router to send/receive packets(messages).

You should look into UDP (user datagram protocol) and TCP (transmission control protocol) if you are interested
in learning how networking works

But if your more interested in just jumping right in and writing applications, you should really take a look at Kryonet (https://github.com/EsotericSoftware/kryonet)
Its a library that makes writing great networked (if thats the right word?) applications very easy and intuitive.

Some code examples from their github :
This code starts a server on TCP port 54555 and UDP port 54777:

1  
2  
3  
    Server server = new Server();
    server.start();
    server.bind(54555, 54777);


This code connects to a server running on TCP port 54555 and UDP port 54777:

1  
2  
3  
4  
5  
6  
7  
    Client client = new Client();
    client.start();
    client.connect(5000, "192.168.0.4", 54555, 54777);

    SomeRequest request = new SomeRequest();
    request.text = "Here is the request";
    client.sendTCP(request);


1  
2  
3  
4  
5  
6  
7  
8  
client.addListener(new Listener() {
       public void received (Connection connection, Object object) {
          if (object instanceof SomeResponse) {
             SomeResponse response = (SomeResponse)object;
             System.out.println(response.text);
          }
       }
    });


For more great code bits or example projects, check out their github.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #2 - Posted 2014-03-29 20:35:35 »

To send and receive packets not in your local network you have to port forward. I have no idea if that's what OP wants though.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Pauler
« Reply #3 - Posted 2014-03-30 09:29:50 »

Only the guy who hosts the server will need to open the ports on the routers configuration page. The players won't need to do anything.

Especially, if your game doesn't allow anyone but you to host a server, there is no reason to worry about, because you are the only one who needs to configurate his ports.
Offline Anju_Maaka

Senior Newbie


Exp: 2 years



« Reply #4 - Posted 2014-03-30 17:23:11 »

@Pauler
Well, it is my hope to be able to publish the game so that anyone can download it and host a server so it'd be really good if I could include some code in the server to open a port in the router automatically when the server starts up. After all, it's good if your game can be used easily by anyone, even those who aren't good at computers.

@saucymeatman
That library really looks good when it comes to sending and receiving stuff. I wonder if it solves my problem though. I couldn't quite make out if it allows you to bypass the problem with the router not knowing which incoming messages that are supposed to be sent to the server on my computer. Do you know if it has an option for "port forwarding" on the router (or what else it might be called, I want my program to be able to tell the router that any incoming message with destination port 6677 (for example) are to be sent to my computer).
Offline Phibedy

Senior Member


Medals: 8



« Reply #5 - Posted 2014-03-30 17:42:12 »

@Pauler
Well, it is my hope to be able to publish the game so that anyone can download it and host a server so it'd be really good if I could include some code in the server to open a port in the router automatically when the server starts up. After all, it's good if your game can be used easily by anyone, even those who aren't good at computers.
Haha that's quite funny, a software that opens ports on any router. Noone will give you his router pw. If you get it working without knowing the password you are on the dark side and quite good at being bad  Wink
But after all you shouldn't need to open ports.
Offline trollwarrior1
« Reply #6 - Posted 2014-03-30 17:54:35 »

You can't open ports like that.

You said that you want people who aren't good at computers to be able to host their own servers. Directing a port to a certain computer on the network isn't being good at computers. Its not like you're making them program something. To open a port all you have to do is change 1 option in router options, which in my opinion, is really easy.

Few things I would like to mention about my past problems with port forwarding:
* After you restart your router/modem or whatever, internal ip addresses change;
* Not all routers can 'target' their own IP address. So for example, if you're hosting a server on your computer, and you try to join your IP (public) address, you might not be able to join it, simply because your router doesn't have ability to connect to itself, so keep this in mind if you are unable to connect to your server;
* Open Port checking sites which check if your port is open only work when there is a service running on that port. So even if you port forward certain port, it will be displayed as closed until you start a service on that port;
Offline jonjava
« Reply #7 - Posted 2014-03-30 19:23:59 »

You can't control this through Java. A prominent use of NAT's is to divide a single IP into potentially unlimited clients/connections (NAT's within a NAT - NATception) and are ill served when using these connections to host content since the IP could be shared by hundreds of devices.

Your ISP additionally might not like/allow hosting, especially if you haven't paid extra.

In general, however, all of the networking mumbo jumbo sorts itself out if you stick with something basic like TCP/UDP and configure your stuff on your own end. Basically it looks like you need to (re)configure your own router.

Offline ewg

Junior Member


Medals: 7


Java games rock!


« Reply #8 - Posted 2014-03-30 20:01:49 »

There is no solution that will work 100% of the time to automatically open ports but many routers support the UPnP protocal and if that is enabled in the router config you can use a java library to use UPnP to open ports. See these links:

https://code.google.com/p/weupnp/
http://upnp-portmapper.sourceforge.net/

There are also other java libraries that attempt to find a way thorough routers without forwarding see here:

http://stackoverflow.com/questions/9656198/java-udp-hole-punching-example-connecting-through-firewall?rq=1


The best solution is of course to get a real server with a public IP address and to host the game there.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2014-03-30 20:07:10 »

OP I think you need to learn a little more about networking first before you make a networked game. Sounds like you don't know all too much yet, no offense.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Anju_Maaka

Senior Newbie


Exp: 2 years



« Reply #10 - Posted 2014-03-30 21:03:39 »

@opiop65
No, I'm afraid I don't know very much at all. The only knowledge I have about it is what I got from a single course in my university program and it dealt with networks as a whole so it didn't go too deep into routers in particular. Still, at least it made me know why it never worked if I tried to host a minecraft server  XD
Offline trollwarrior1
« Reply #11 - Posted 2014-03-31 04:38:56 »

Make a game that someone wants to play and host servers and worry about port forwarding later..
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

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

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

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

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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!