I'm trying to implement a multi-state, multi-state client application, and you have some questions about creating network / streaming projects. The problem I'm currently facing is messaging between the communication layer and the logical layer.
The server processes several clients, each of which can be active in several "channels", where each channel has several stages and can have several clients operating in it. Think about it with something similar to a multi-room chat program.
I have already implemented receiving messages on the server side. Each client has its own stream, which blocks the reading of data and decodes them into a message. Now how to proceed? In my presentation, each channel should also have its own stream in order to easily maintain its state. I could use BlockingQueue to exchange received messages with a channel stream that blocks waiting for new messages in this queue.
But then how to send messages to clients? The logic in the channel will process the message and create some messages for sending to one / several / all clients. Is it safe to use a channel stream to write directly to a socket? Or should I use another BlockingQueue to pass messages to the client handler thread? But how to wake him up, since he is waiting for the socket to read? Or should I use a separate send stream for each client or even a separate send-socket?
BTW: I know that I could use existing libraries for the network layer, but I want to do this from scratch on simple sockets.
source share