Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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  
  Client threads in a thread-per-client online game  (Read 2165 times)
0 Members and 1 Guest are viewing this topic.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Posted 2014-05-31 03:48:15 »

I heard the old paradigm is the new thing, so I abandoned NIO for now.

That is the best practise for Threads on the client, when using standard java Sockets? One thread for UI, and one for networking? Should I just reference the networking Thread in the UI-instance?

How would they communicate? Adding packets to a thread-safe queue for sending to the server, and then looping checking if there is something to be read from the InputStream? Is it okay to have both input and output on the same thread?

How would this networking thread work? I can't just loop (apparently) because reading from the inputstream will block.

So how is this done? Examples and pseudocode are appriciated Smiley

Online BurntPizza

« JGO Bitwise Duke »


Medals: 289
Exp: 5 years



« Reply #1 - Posted 2014-05-31 03:54:10 »

I don't have a real answer for you, but I will say that you will save yourself a lot of time and hair if you use a working third party solution like Kryonet.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #2 - Posted 2014-05-31 03:57:54 »

I don't have a real answer for you, but I will say that you will save yourself a lot of time and hair if you use a working third party solution like Kryonet.

Thanks for suggestion, but I already have used KryoNet once before. I would like to try using the low-level Sockets and get a feeling for what is going on under the hood.


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

« JGO Bitwise Duke »


Medals: 289
Exp: 5 years



« Reply #3 - Posted 2014-05-31 04:03:58 »

Well then I direct you to the tutorial series on game networking by Glenn Fiedler: http://gafferongames.com/networking-for-game-programmers/
Actually I guess it's not really a series, so just read them in any order you like, but defiantly read all of them, they're pretty great IMO.
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #4 - Posted 2014-06-02 09:30:39 »

Since I'm having trouble with Threads using blocking IO with Swing, I'm jumping to LibGDX with Kryonet. I have one question however.

Is a single thread enough for both the clients networking and it's UI updates? I know this is not possible with blocking IO, but is Kryonet sufficiently fast for my framerate not to drop dramatically?

Offline theagentd

« JGO Bitwise Duke »


Medals: 365
Projects: 2
Exp: 8 years



« Reply #5 - Posted 2014-06-02 13:25:27 »

Is a single thread enough for both the clients networking and it's UI updates? I know this is not possible with blocking IO, but is Kryonet sufficiently fast for my framerate not to drop dramatically?
If your networking code has a performance impact at all you're doing something VERY wrong. Any time proven library will be fast enough. Unless you're creating a server for hundreds of simultaneous players, your choice of library should only be based on convenience.

Myomyomyo.
Offline snacktime

Senior Newbie


Medals: 1



« Reply #6 - Posted 2014-06-04 16:21:48 »

I heard the old paradigm is the new thing, so I abandoned NIO for now.

That is the best practise for Threads on the client, when using standard java Sockets? One thread for UI, and one for networking? Should I just reference the networking Thread in the UI-instance?

How would they communicate? Adding packets to a thread-safe queue for sending to the server, and then looping checking if there is something to be read from the InputStream? Is it okay to have both input and output on the same thread?

How would this networking thread work? I can't just loop (apparently) because reading from the inputstream will block.

So how is this done? Examples and pseudocode are appriciated Smiley

It would be a slight learning curve, but Akka (http://akka.io) would change your life forever when dealing with threading, and it has networking built in.  I use it on a large server multiplayer engine, but it's light enough to use on the client.  It basically gives you a high level abstraction for threading and networking that is just better then anything else currently out there in java.

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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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