Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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 1062 times)
0 Members and 1 Guest are viewing this topic.
Offline fubz

Senior Newbie


Projects: 1



« Posted 2005-10-29 01: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:

Client:
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


Server:
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 03:42:10 »

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

0,45,100|1,100,60|2,30,20

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

playerID,X,Y

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 09: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.

Alan

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 Member




Java games rock!!


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

Quote
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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (64 views)
2014-04-15 18:08:23

BurntPizza (62 views)
2014-04-15 03:46:01

UprightPath (75 views)
2014-04-14 17:39:50

UprightPath (58 views)
2014-04-14 17:35:47

Porlus (76 views)
2014-04-14 15:48:38

tom_mai78101 (101 views)
2014-04-10 04:04:31

BurntPizza (161 views)
2014-04-08 23:06:04

tom_mai78101 (256 views)
2014-04-05 13:34:39

trollwarrior1 (209 views)
2014-04-04 12:06:45

CJLetsGame (216 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!