How to Handle Chat Messages Asynchronously in Java

javamessaging

I'm working on a program where part of it will be working as a chat between different people. I'm trying to figure out the best way to send and receive messages.

A PrintWriter or something similar won't work because the process will stop at the read() method while waiting for a message to be sent to it. I'd like to check to see if there is a new message, and if not, continue the execution.

I've seen some stuff about JMS, but I haven't done enough research to determine if it's up for this job.

Is JMS the best option for this, or is there a better way?

Best Answer

You might want to check Netty.

Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server.

Related Topic