1
votes

1, my server has a ServerSocket to accept client connection 2, my client create a socket and and send message to the server. 3, the server gets the message and reply to the client.

So it's always the client that initiate the communication.

Say some time later after initial client connection, the server wants to send another message to the client, is it possible to do so?

2

2 Answers

5
votes

If you keep the socket connection from the client open on the server yes. The client would need to be always listening for data coming in.

Otherwise the client will have to poll in intervals to the server if the connection on the server is closed after a message is sent.

1
votes

The client must always initiate the connection, that's pretty much the only distinction between a server and a client (a program can be both be a server and a client).

However once a connection is established, as long as it's not closed either side can send data to the other (assuming the other side is listening for data).