Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (577)
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  
  [SOLVED][Kryonet]Networking Protocol?  (Read 758 times)
0 Members and 1 Guest are viewing this topic.
Offline bilznatch

Senior Duke


Medals: 8
Projects: 2
Exp: 1 year


I'm bad, I'm bad, I'm really... really bad T_T


« Posted 2013-08-20 22:53:16 »

So, I've been experimenting with networking using kryonet, and I have written a really simple 2-client demo, basically just giving each other coordinates as they move.

My question is, in what way should I write my client-server architecture?
Should I convert to UDP and use datagrams, or should I stick with TCP and write a player object with all the information needed inside, and send that?
Do I send updates at the same rate as I render, less often, etc? (updates are sent on the render thread every 6 frames through the client object, but it receives in it's own thread, I know I could write this based on a timer in the client thread or in it's own send thread as well, but I don't know how necessary that is)

All I really need are some good resources. Feel free to post examples if you have written network code before. (I'm not interesting in interpolation or anything as of right now, I just want something usable, I'm more interested in the networking side, rather than what a user would see, as the only user is myself)
Offline Andre Lopes
« Reply #1 - Posted 2013-08-23 02:53:10 »

So, I've been experimenting with networking using kryonet, and I have written a really simple 2-client demo, basically just giving each other coordinates as they move.

My question is, in what way should I write my client-server architecture?
Should I convert to UDP and use datagrams, or should I stick with TCP and write a player object with all the information needed inside, and send that?
Do I send updates at the same rate as I render, less often, etc? (updates are sent on the render thread every 6 frames through the client object, but it receives in it's own thread, I know I could write this based on a timer in the client thread or in it's own send thread as well, but I don't know how necessary that is)

All I really need are some good resources. Feel free to post examples if you have written network code before. (I'm not interesting in interpolation or anything as of right now, I just want something usable, I'm more interested in the networking side, rather than what a user would see, as the only user is myself)

Well, TCP you have the packet that check for errors, so your data is less suitable for errors.
in UDP you dont, but it depends on the project. For me, in my chat server/client , i used TCP , and im glad i did...
Offline Jeremy
« Reply #2 - Posted 2013-08-23 03:20:03 »

So, I've been experimenting with networking using kryonet, and I have written a really simple 2-client demo, basically just giving each other coordinates as they move.

My question is, in what way should I write my client-server architecture?
Should I convert to UDP and use datagrams, or should I stick with TCP and write a player object with all the information needed inside, and send that?
Do I send updates at the same rate as I render, less often, etc? (updates are sent on the render thread every 6 frames through the client object, but it receives in it's own thread, I know I could write this based on a timer in the client thread or in it's own send thread as well, but I don't know how necessary that is)

All I really need are some good resources. Feel free to post examples if you have written network code before. (I'm not interesting in interpolation or anything as of right now, I just want something usable, I'm more interested in the networking side, rather than what a user would see, as the only user is myself)

UDP is for when things such as message order isn't critical and when missing messages on occasion won't break your networking model. For example, sending entity coordinates every time they change would be UDP since missing a coordinate doesn't really matter when the next one is milliseconds away.

With Java you can very easily serialize data across the network and use things such as Remote Method Invocation (Provided by Kryonet and the JDK) So you should take advantage of that if you can. You should also take advantage of  the TCP\IP protocol if you can as well since it is much less error prone.

Anyway, when it comes to some general hints for networking your game:

 - Most of the time, your bottlenecks will be bandwidth and network speed, so don't be afraid to spend some CPU time compressing the data your are transmitting across to clients\peers.

 - Abstract the networking to as high of a level as possible. You talked about constantly sending X\Y coordinates? Well, it would be more useful to the client if you sent the velocity, acceleration and position and then you can send the coordinates much less frequently and implement some sensible client-side prediction. If your game is more predictable in terms of player movement (i.e, tile based) you can abstract it much further and notify clients when an entity is moving to another tile and have them perform the remainder of the logic client-side.

The basic principal for a centralized server (I'm not sure which model your after, but this one is very common) is to do something like the following:

1. Server thread waits for incoming connections, upon request for connection, it is accepted.

2. Server spawns another thread, that acts as a sort of 'sub-server' for just that accepted connection. The subserver will handle all communications from just that particular client. Since the subserver runs in a different thread, the server is now free to go back and repeat step one (listen for more clients)

3. The subserver querys the state of the game from the server, and helps initialize its respective remote client.

4. When the spawned subserver receives a command from the client it will notify the server which spawned it that its corresponding client has issued a command (i.e picked up item, moved somewhere) and the server will broadcast that command to all other spawned sub-servers.

It is a little more involved than that, and not being very into networking myself I might have used the improper terminology there (others are welcome to correct me) but that is the basic gist of it.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elamre

JGO Coder


Medals: 17
Projects: 1


hitar!


« Reply #3 - Posted 2013-08-23 09:09:34 »

Thats the same as i have it. With one central server and one thread for every client holding all the information (both network information and game information), but i dont think its quite the same way with udp since udp isnt blocking if i'm correct.
In UDP it also checks for some errors(in system level). if any errors have occured the packet will be dropped.

My projects:
Tower Defence!]http://www.java-gaming.org/topics/iconified/25690/view.html]Tower Defence! [lll.......] 30%!
Lightsnakerider! [llllll....] 60%!
Offline bilznatch

Senior Duke


Medals: 8
Projects: 2
Exp: 1 year


I'm bad, I'm bad, I'm really... really bad T_T


« Reply #4 - Posted 2013-08-23 15:26:41 »

Seems it's pretty much as I expected. Unfortunately.
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 (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!