multiple clients - single server application, each as separate processes

Selçuk Cihan selcukcihan at gmail.com
Fri Feb 15 08:32:41 PST 2008


Hi, i have two separate projects one implementing the server and other
implementing the client. I have coded only very little and i am
currently working on server.

Scenario: One server process and multiple client processes. Each
process may be running on different cpus. The processes will
communicate through wxsockets. Clients send messages to server, the
server recieves messages and perform some work and then return the
results to each client. So for one incoming message, the server
replies to each client, lets say it broadcasts the reply.

I have been reading about wxthreads and wxsocketclient and
wxsocketserver. I am stuck at the design phase, how should i proceed?
What threads should i create? And how should those threads run in
harmony

At the moment i have two ideas in mind.

First one involves way too many threads so i guess i have some redundancy:

1) There is a the main thread (gui), call T1
2) There is an AcceptClientThread which continously listens for
incoming connection requests (uses wxsocketserver), call T2
3) There is a ProcessorThread, call T3.
4) There is a MainSenderThread, call T4
5) There is a ListenerThread, call T5, for each client, has a unique socket
6) There is a SenderThread, call T6, for each client, has a unique socket

Now, i have two buffers to store messages. InBuf is where i put
incoming messages from clients. OutBuf is the buffer to which i put
outgoing replies to clients.

T3 is always running and getting from InBuf, then processing and then
putting the outcome to OutBuf. For each client, one T5 is running and
reading from the socket and putting the message to InBuf.
MainSenderThread is always trying to get from OutBuf and pass the
reply to each T6. Each T6 gets the reply from T4 and writes this to
its member socket.

T3 T4 and T5 are started from T1 when the first client connects. When
a client connects, T2 tells T1 about it and gives the serverside
socket. T1 takes this socket and creates a T5 giving this socket as
parameter. Also, T1 tells T4 about the new client and gives the
address of the client(obtaining it from serversocket.GetPeer(). T4
creates a T6 giving the address of client, T6 uses wxsocketclient and
creates a socket using this address.

Idea two is not very clear, i believe this application perform with
only 3 kind of threads. One thread is the main thread, second is
accepting connections and the third kind of thread represents a
client. So for each client i will have a thread, it will read/write.
Connection accepting thread is the one creating the client threads.
Each client thread has its own InBuf and OutBuf. Main thread can do
the processing by retrieving messages from InBufs and writing to
OutBufs.

Any ideas truely appreciated. Have a nice day.




More information about the wx-users mailing list