Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (686)
Games in Android Showcase (197)
games submitted by our members
Games in WIP (758)
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  
  Network: slow client update  (Read 1360 times)
0 Members and 1 Guest are viewing this topic.
Offline fubz

Junior Newbie

« Posted 2005-10-28 23:34:49 »

I have a platform type game, and i've been trying to get multiplayer working. I succeeded, BUT, the client doesnt update fast enough so everyone just teleports as they move, even on a LAN.

What i am doing is:

Thread 1:
- gathers players pos (thats all at the moment, i would hope to add more, but its too slow as it is)
- Stores values in Object array, serializes, and sends

Thread 2:
- handles game

Thread 1:
- Waits for players to connect
- Starts new Thread to handle client

Thread 2:
- reads players data, deserializes data, stores player(X's) data into static array full of everyone elses data so it can be serialized and shipped off.

I was reading through the forums, and someone mentioned that sending objects is slow, so that might be the reason. But if i cant send objects how am i to send data for say 8 players to the client?
Offline woogley
« Reply #1 - Posted 2005-10-29 01:42:10 »

just create your own format for the player's position for the client to send. Just, for example:


That's basically the player data stored in a triplet format separated by a | character. Format is:


So just send a string like that to the server and parse it with StringTokenizer or regex.
Offline Alan_W

JGO Knight

Medals: 8
Projects: 3

Java tames rock!

« Reply #2 - Posted 2005-10-29 07:28:02 »

I use a NIO ByteBuffer in SharpShooter Arena.  There are methods for reading/writing bytes, shorts, floats etc., so you can create a custom packet quite quickly.  Manual packet creation scores over serialisation in that no structural information about the object is transmitted.  This can save precious bytes when sending position updates at a high rate over a 56k modem connection.  It's so easy to exceed the maximum throughput with multiple users.

Of course this does use NIO.  Using NIO also reduced the number of threads and avoided having to synchronise all over the place.  There are bugs in it, although keeping my usage as simple as possible avoided any problems in my case.

My solution was to open a UDP port for listening.  Each time a packet arrives, the sender IP address:port identifies the remote client.  The first byte of each packet identifies the packet type.  This is followed by the payload in one of a range of fixed data formats.  Sending consists of assembling the packet, addressing it to the client address:port & off it goes.  The sending operation may block or lose packets if you send faster than the local connection can transmit.

UDP is great for streaming position updates.  You can get problems when transmitting state (e.g. player X killed), since packet loss can occur.  A higher level reliable transfer protocol is then required.


Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bitshit

Junior Devvie

Java games rock!!

« Reply #3 - Posted 2005-12-06 08:50:09 »

UDP is great for streaming position updates.  You can get problems when transmitting state (e.g. player X killed), since packet loss can occur.  A higher level reliable transfer protocol is then required.

Did you use a additional TCP socket for that in Sharpshooter?
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

roseslayer (374 views)
2016-08-06 11:43:29

roseslayer (342 views)
2016-08-06 09:43:11

xTheGamerCodes (418 views)
2016-08-04 15:40:59

xTheGamerCodes (409 views)
2016-08-04 15:40:24

orrenravid (761 views)
2016-07-16 03:57:23

theagentd (836 views)
2016-07-11 14:28:54

Hydroque (927 views)
2016-07-06 05:56:57

Hydroque (972 views)
2016-07-03 08:52:54

GrandCastle (783 views)
2016-07-01 09:13:47

GrandCastle (634 views)
2016-07-01 09:09:45
Rendering resources
by Roquen
2016-08-08 05:55:21

Rendering resources
by Roquen
2016-08-08 05:52:42

Rendering resources
by Roquen
2016-08-08 05:50:38

Rendering resources
by Roquen
2016-08-08 05:49:53

Rendering resources
by Roquen
2016-08-08 05:32:39

Making a Dynamic Plugin System
by Hydroque
2016-06-25 00:13:25

Java Data structures
by BinaryMonkL
2016-06-13 21:22:09

Java Data structures
by BinaryMonkL
2016-06-13 21:20:42 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‑
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!