Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
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  
  Kryonet - Local Connection works, External doesn't  (Read 5508 times)
0 Members and 1 Guest are viewing this topic.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Posted 2012-09-28 20:45:34 »

Hey,

I recently started out with networking but I already ran into a brickwall, my knowledge of networking is very little so I hope the fix will be rather simple.

Basically, I'm using Kryonet and so far just used the sample code on the page, so Running a Server and Connecting a Client, altered it a little so I can increase a number on the server by pressing space on the client... which works BUT
only when I do it on the same computer with 127.0.0.1 OR I also tried it on two different laptops which are connected to the same Router and used the (I guess internal?) IP 10.0.0.1 .... both worked

But when I tried to connect to the server with the IP I get from for example http://www.whatsmyip.org/ it doesn't work, unable to connect.

Server
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
public class KryoServer {

   public KryoServer() throws IOException{
      Server server = new Server();
      server.start();
      server.bind(54555, 54777);

      Kryo kryo = server.getKryo();
      kryo.register(SomeRequest.class);
      kryo.register(SomeResponse.class);
     
      server.addListener(new Listener() {
            public void received (Connection connection, Object object) {
               if (object instanceof SomeRequest) {
                  Main.test++;
                 /* SomeRequest request = (SomeRequest)object;
                  System.out.println(request.text);

                  SomeResponse response = new SomeResponse();
                  response.text = "Thanks!";
                  connection.sendTCP(response);   */

               }
            }
         });
   }
}


Client
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public class KryoClient {
   
   Client client;
   String IP;
   
   public KryoClient(String IP) throws IOException{
      this.IP = IP;
      client = new Client();
      client.start();
      client.connect(5000, IP, 54555, 54777);

      Kryo kryo = client.getKryo();
      kryo.register(SomeRequest.class);
      kryo.register(SomeResponse.class);
     
      client.addListener(new Listener() {
            public void received (Connection connection, Object object) {
               if (object instanceof SomeResponse) {
                  SomeResponse response = (SomeResponse)object;
                  System.out.println(response.text);
               }
            }
         });
   }
   
   public void sendRequest(){
      SomeRequest request = new SomeRequest();
      client.sendTCP(request);
   }
}


Thanks
Offline deathpat
« Reply #1 - Posted 2012-09-28 23:37:54 »

I think you just have to configure your router to forward the ports you're using (54555, 54777) to the local IP on which your server is running ( 10.0.0.1 ) Wink

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

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #2 - Posted 2012-09-29 00:15:21 »

Are you sure I need to forward my ports?

Prime example Minecraft, I click join, type in the server's IP and bam I'm in. What advantage does Minecraft have? That they use a login-system and connect Clients and Servers via accounts? But why would that eliminate the need to forward the ports? I'm kind of confused... i dont think it's the firewall, I disabled it on the laptop I launched the server  Grin

Thanks, appreciate your advice
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cubemaster21
« Reply #3 - Posted 2012-09-29 00:45:05 »

Port forwarding is necessary for people outside of your home's network to access the server. Not the other way around.You don't need to port forward your computer if you are connecting to someone else's server.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #4 - Posted 2012-09-29 01:09:07 »

Oh snap, I see. Will check tomorrow if that fixes the problem.

Thanks!
Offline atrakeur

Junior Newbie





« Reply #5 - Posted 2012-09-30 21:27:04 »

Look at Nat-punchtrough ;-)
It's a way to make connection possible with server behind routers.
I've achieved that in C# but because sockets and IP protocol are the same in all languages I think you can do that in java.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #6 - Posted 2012-10-02 05:07:28 »

I just discovered that my millions of collision-avoidance attempts never satisfyingly worked because I didn't cast the integer values to float... I feel an inner, deep, deep, creeping rage but also relief that it seems to work now.

Not really ontopic but I just had to express my feelings in a textual way. Thank you.
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #7 - Posted 2012-10-06 04:54:58 »

I have another Kryonet question but I dont think it's worth opening another thread.

I'm a little confused on how to design things.
Right now, if a client joins the server, instead of sending the client all the Players (the objects) I just send the players' x and y coordinates and let the client create it's own Player objects based on this information. Partially to send less data and partially because sending the whole Player object didn't seem to work  Grin

Is this a good way of doing it? Because now I added the ability that the Players can carry objects, if now a client joins the server it doesn't get the information that one of the players is already carrying an object, since it's building its own Players based on the x and y coordinations I send to it.
Now an obvious solution to that would be, that besides sending only the x and y coordinates I also send the information what object the player is carrying.... but I can see this growing to more and more information and giving me a major headache

Feedback appreciated
Offline cubemaster21
« Reply #8 - Posted 2012-10-06 18:36:02 »

I'm no expert in this area, but are you sending all of the X's and Y's separately? My thought would to make a "PlayerPacket" class that contains all of the data that you need to send and send that at once.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #9 - Posted 2012-10-07 07:40:55 »

I send a float[][] array with all the x and y values, and the player's ID. Now I also added a string for the type of object the player is carrying.

Now I only have one type of object the player could carry, but obviously that will change. So I will have to do quite a bunch of if-else checks to see what object the client has to create.
Oh well, this is pretty much my first game (that actually looks like a game) and I started with Multiplayer right away, I ecpect it to fail eventually  Tongue
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cero
« Reply #10 - Posted 2012-10-23 15:41:41 »

So you need to open ports on the server app's side.
What about android online gaming ? If I dont use Wifi its the ISP... will it just work ?

Offline dragonheartman

Junior Member


Medals: 9
Projects: 1



« Reply #11 - Posted 2012-11-01 23:45:33 »

I have another Kryonet question but I dont think it's worth opening another thread.

I'm a little confused on how to design things.
Right now, if a client joins the server, instead of sending the client all the Players (the objects) I just send the players' x and y coordinates and let the client create it's own Player objects based on this information. Partially to send less data and partially because sending the whole Player object didn't seem to work  Grin

Is this a good way of doing it? Because now I added the ability that the Players can carry objects, if now a client joins the server it doesn't get the information that one of the players is already carrying an object, since it's building its own Players based on the x and y coordinations I send to it.
Now an obvious solution to that would be, that besides sending only the x and y coordinates I also send the information what object the player is carrying.... but I can see this growing to more and more information and giving me a major headache

Feedback appreciated
I would only send the positions out when they change (and the packet was sent successfully!). If the client is standing still, there's no reason to constantly send the player coordinates.

You could try sending different types of packets with a small identifier at the start of the packet, so the server/clients know how to handle each identifier's data while also cutting down on packet size.

PS, how are you liking kryonet?
Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #12 - Posted 2012-11-02 01:42:24 »

PS, how are you liking kryonet?

I've given up on multiplayer for now, because I think I need to gather more experience till I can dive into that, given that it is a rather complex field.

But yes, Kryonet is awesome! I had no multiplayer experience whatsoever before I started using Kryonet, but got everything to work that I wanted! (at least locally it did)

I would recommend it anytime  Pointing
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 (18 views)
2014-08-28 18:26:30

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

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

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

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

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

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

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

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

BurntPizza (37 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!