问题
Is it possible to implement a custom WebSocket app in Java without having to run it on a Web-Server like GlassFish, Tomcat, Jetty etc?
I intend to develop a very custom-tailored App and would like to implement my own way to manage threads, monitoring, load balance, messaging and stuff like that. (compared with e.g. Java TCP’s ServerSocket ) I know there are Tyrus containers such as Grizzly integration for standalone server and Servlet support and here is Jetty as well, but I am not sure if that is what I am looking for. Is Grizzly or Jetty perhaps a standalone solution per se? I know Tyrus is some kind of wrapper for Grizzly WebSocket Implementation but to be honest, I am not sure how those two are interconnected.
Any suggestions are more than welcome! Thank you!
回答1:
In other words, you're trying to implement a WebSocket server, something like:
https://code.google.com/p/jwebsocket/ (link is dead)
http://jwebsocket.org/downloads/jwebsocket-latest-versions (new link)
回答2:
Tyrus is not "some kind of wrapper of Grizzly", but it can run on top of it.
(Tyrus is Reference implementation for WebSocket API for Java (JSR 356), which is part of Java EE).
Running without web server (assuming you are talking about appserver or something "big") is perfectly possible and very simple, since we are using this for our "e2e" testing. (I'm Tyrus developer if that matters).
Starting new container which can process WebSocket connections is as simple as: Main.java , see project declaration [pom.xml] for complete list of dependencies.
来源:https://stackoverflow.com/questions/33415121/using-java-websocket-api-implementation-without-a-web-server