Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (710)
Games in Android Showcase (212)
games submitted by our members
Games in WIP (784)
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  
  2 way server <-> client communication  (Read 2316 times)
0 Members and 1 Guest are viewing this topic.
Offline Kova

Senior Devvie

« Posted 2006-04-12 00:26:57 »

So for my game I have a server thread (S) and packet sender thread (PS). First I was gonna ask about the problem I had with client not geting servers packets, but during writing I figured out what I missed and corrected it.
Now I ask for opinions, is this good way to program networking or there are better ways? Like most stuff beyond connecting and receiving data on one side, I did this myself couse there are no tutorials or books on how to do server - client thing right way (beyond trivial connecting to server, sending data and server responding to received data), at least I couldn't find them. Tell me what do you think of this logic:

S waits for connection in non-blocking mode. Client connects and S accepts. On clients side channel is register for OP_READ, set to non-blocking mode and added to clients list after establishing the connection to server, and on server side all that is done when accepting connection. Both sides have now S that listens for that channel's data, and a PS that sends data through the channel on the other side every X seconds. If error occurs or connection is closed then channel is removed from clients list and closed (thus deregistering OPs as I understood). If more clients connect to server they will be added to the clients list and PS on server side goes through the list, sending everybody data. So S and PS on both ends are the same except they have IF statements do process server's or client's packets differently.

That's that.
Oh yeah I find the biggest problem is actually synchronizing the data so threads won't access it at the same time... and I've got a lot of data shared between 3 threads (animation, S, PS). It's really annoying and I was thinking of restructuring things so they share less data. For example, for client to send players stats and position, PS needs to access animation thread and take the data... same thing about processing received data where S needs to set animation's variables and so on... don't get me started how many data S i PS share... If there is a good book or tutorial who would describe the best logic for this I would be gratefull. Thanks to all for reading this huge post Wink
Offline CommanderKeith
« Reply #1 - Posted 2006-04-12 03:57:05 »

So for my game I have a server thread (S) and packet sender thread (PS).

If you are using non-blocking channels there's no need to have a thread per connection to send packets - that was only needed for old IO when you had to block.  It would be better to have one thread for the server which sends packets to all clients.  For listening to connections you can do that in the same thread or have a separate one that blocks - I do the latter since then you can pause the game loop thread without stopping incoming connections - i don't think that there's any threading issues with doing this either (at least I haven't had any).

Offline Kova

Senior Devvie

« Reply #2 - Posted 2006-04-12 08:44:02 »

you missunderstood, I said I have a server thread and packet sender thread. That's 2 threads. Didn't mentioned nothing about thread per connection.
About having server thread that listens and sends data, how do you do that? How would I implement sending every X ms? ... for now I sleep in packet sender thread for X ms.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

theagentd (86 views)
2017-02-18 13:42:33

theagentd (90 views)
2017-02-18 13:35:16

h.pernpeintner (1256 views)
2017-01-24 22:39:11

h.pernpeintner (1245 views)
2017-01-24 22:38:32

Galdo (1803 views)
2017-01-12 13:44:09

Archive (1909 views)
2017-01-02 05:31:41

0AndrewShepherd0 (2446 views)
2016-12-16 03:58:39

0AndrewShepherd0 (2292 views)
2016-12-15 21:50:57

Lunch (2371 views)
2016-12-06 16:01:40

ral0r2 (2155 views)
2016-11-23 16:08:26
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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!