EDIT: removed reference to C# as the only accepted answer is about Java. If someone needs information about websocket server implementation in C#, ask a new question.
Do you know "production ready" framework for creating WebSockets Server in Java? I found one library http://nugget.codeplex.com/ but i did not know how it is stable and fast.
By default, a single server can handle 65,536 socket connections just because it's the max number of TCP ports available.
Spring Boot includes the spring-WebSocket module, which is compatible with the Java WebSocket API standard (JSR-356). Implementing the WebSocket server-side with Spring Boot is not a very complex task and includes only a couple of steps, which we will walk through one by one.
The accepted answer is 3 years old, with the recent release of JEE7, now every Web Containers that implement servert 3.1 will support websocket via standard API (javax.websocket) package.
The following code show example how to implement websocket using JEE7:
import java.util.logging.Level; import java.util.logging.Logger; import javax.websocket.OnClose; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; @ServerEndpoint(value = "/chat") public class ChatServer { private static final Logger LOGGER = Logger.getLogger(ChatServer.class.getName()); @OnOpen public void onOpen(Session session) { LOGGER.log(Level.INFO, "New connection with client: {0}", session.getId()); } @OnMessage public String onMessage(String message, Session session) { LOGGER.log(Level.INFO, "New message from Client [{0}]: {1}", new Object[] {session.getId(), message}); return "Server received [" + message + "]"; } @OnClose public void onClose(Session session) { LOGGER.log(Level.INFO, "Close connection for client: {0}", session.getId()); } @OnError public void onError(Throwable exception, Session session) { LOGGER.log(Level.INFO, "Error for client: {0}", session.getId()); } }
Example in details here.
Web Container that support Websocket:
For Java, check out this informative post. Copy-paste from there:
Out of these options, I guess Jetty and Resin are the most mature and stable. However, always good to do your own testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With