Reputation: 2077
Is it possible to implement a Java based server both HTTP requests and listening to websockets? I would like to response JSON objects to HTTP clients and customer objects to websocket clients.
Upvotes: 0
Views: 116
Reputation: 1760
Yes, This is possible. A web server will anyway respond to HTTP requests given that you have implemented servlet/s that match the paths clients are requesting. You can use a servlet container to host your servlets. When you say Sockets(not web sockets) I assume that you're talking about opening a port where Java server will be listening to any UDP or TCP based requests that may be coming through internal network or from other network. You can find many source code samples for implementing a UDP or TCP server that listens on a given port.
Also note that opening multiple ports on the server opens up a security threat if port is visible to outside network.
Upvotes: 1