Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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  
  Multithreaded or SelectNow?  (Read 1680 times)
0 Members and 1 Guest are viewing this topic.
Offline squidi

Junior Newbie

Lord of the Pants

« Posted 2006-06-06 02:13:13 »

I'm writing a mud, and I've got it to a point where people can connect and walk around and all sorts of fun stuff. I'm having a little conceptual trouble with how to communicate between two threads. It actually works, but I don't understand enough about what I'm doing to know if it will always work, or if I'm doing something which may hurt me later. Working between multiple threads is new to me, and I'm wondering if it might just be easier to go single threaded.

Basically, what I'm doing is as each client finishes receiving a completed line of text, that text is put into a command queue for that client. Then the other thread goes through all the clients, checks if they have a command, and if they do processes it. I'm already aware that the client list may change in the middle, so I'm thinking I'll have to use a separate list to hold clients with commands pending. But the queue for each client is synchronized, so I don't think  moving the commands between threads is a problem. And while the client does change during the course of the program, the parts the world model uses and the parts the server uses are pretty separate, such that I don't think either one will step on the other's toes.

Basically, I'm asking if this approach will work, of if there is a better approach to this problem out there? I'm new to both multiple threads and to network programming, so I'm really in over my head and pretty unsure about everything.

Visit my webcomic:
Offline Sakazaki

Junior Newbie

« Reply #1 - Posted 2006-06-06 07:55:34 »

I think it works if all threads read/write commands queues in a synchronized environment, as you suggest.
If I understood your approach basically you have a server thread that pool all active clients queue, process each command, and send a response throw client connection.
The only thing to take care in such solution is to synchronize queues (both clients and server), well... it not soo difficult, but debugging can be a nightmare if something do not work as expected (there are something wrong in client threads? in server thread? in queues synchronization?).
When I developed a mud server I choose to do it in a different way.
Each player is an object that "speak" with the clinet throw a connection (so one player one thread as in your solution, but only for I/O), a player receive a command string and pass the command to a command manager with a reference to itself. No queue in the "client side", only a command queue in the "server side" (server thread).
When the command manager receive this instruction process it and, if there are some feedback for player, use the payer reference to perform back comunications.
It's a quite similar approach, but I have only one command queue and I don't have a thread that "pool" each active connection; my server thread waits command from players and process it in a First In First Out way.
I don't know if this is the "best way to do this"(TM), just an idea.
I think develop a mud environment is an interesting exercise, there are a lot of possibilities to do the same things  Grin

Have a good job  Wink
Pages: [1]
  ignore  |  Print  

ivj94 (582 views)
2018-03-24 14:47:39

ivj94 (47 views)
2018-03-24 14:46:31

ivj94 (374 views)
2018-03-24 14:43:53

Solater (61 views)
2018-03-17 05:04:08

nelsongames (108 views)
2018-03-05 17:56:34

Gornova (150 views)
2018-03-02 22:15:33

buddyBro (693 views)
2018-02-28 16:59:18

buddyBro (91 views)
2018-02-28 16:45:17

xxMrPHDxx (493 views)
2017-12-31 17:17:51

xxMrPHDxx (730 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!