Java – selecting between SocketChannel and stdin?

  Kiến thức lập trình

I’m building a Chat application in Java (educational purpose project), which is client-server architectured. It is a console application.

The client and server communicate using a TCP connection.

On the client side, I want the program to be able to receive messages from the server (when another user sends this user a message for example), but in the same time, the program should be able to take user input (for example – to send another user a message).

Ideally, I would want to use Selector to select between the socket and System.in, but from what I understand, there is no straightforward way to do this.

Any idea?

LEAVE A COMMENT