Dear Jun, It is not always necessary that the server would be able to contact the client. For example, when the server is behind a firewall and all clients have private IP addresses, the server would not be able to contact the clients. Not only that when you have large number of clients, there would be 2 socket connections either way for each client so that also may not be a good idea.
Since the client and server are using sockets, it is better if you send the push message to the client directly over the socket. However, if the socket breaks, you can keep the push message at the server side memory for some time till timeout. I suggest that when clients receive the messages from the server, they can acknowledge so that the server knows for sure that clients got the message. Whenever client's connection with server breaks, it should make a new connection. Another idea would be that the client should keep sending very light sort of messages to the server periodically and if server does not receive anything from client socket it should timeout the socket i.e. close it. Regards, Archanaa -----Original Message----- From: Jun Dai [mailto:[email protected]] Sent: Thursday, April 23, 2009 7:37 PM To: [email protected] Subject: How can tcp server actively send messages to client? Hi All, I'm working on a server / client application using MINA. The server and client communicates by tcp. In some situations, server would actively push messages to client. How to design? The server can directly write messages to the session, but what if the session is closed (for instance the network is broken) ? To try to connect to server when session closes every time and keep try or set up a MINA server also on client side and server using MINA client to send message to the client? Thank you. -- Best Regards DAI Jun Important notice: This e-mail and any attachment there to contains corporate proprietary information. If you have received it by mistake, please notify us immediately by reply e-mail and delete this e-mail and its attachments from your system. Thank You.
