Java – Any disadvantage to using websockets for non-web client apps

client-serverjavawebsockets

this is my first post on here. I am wondering if there is any disadvantage to using websockets as a communication method for a non-web-based client application to connect to a server?

I am looking at designing a turn-based game, using a client-server approach. I would like to design the game server so that different types of clients can connect to it. Some might be web-based (in which case a websocket seems ideal); however, others might not be browser-based. If I could use websockets for all of them, I would think that might simplify the server-side implementation.

However, there must be some downsides to using websockets, otherwise every client-server application would be using them, right?

(btw, I am planning to implement the server in Java)

Best Answer

While websockets is a very convenient protocol to use for all kinds of internet-connected clients, there are potential disadvantages when non-web clients are involved, based on the availability of suitable communication libraries. At least when some clients will be based on web browsers, as for added web programming convenience, you may want to use a protocol such as Socket.IO on top of the websocket communication.

You state that you plan to implement the server in Java, but you do not mention on what platforms the non-web clients might be implemented. Before deciding on the protocol, you should try to define the most likely programming environments for the clients and check out the availability of client libraries that work with the intended server libraries.

For example, .NET has the Microsoft-maintained SignalR client libraries, but there is no SignalR server for Java. And while there are Socket.IO servers for Java, the clients that exist for .NET may or may not be stable enough. The currently most frequently NuGet-downloaded client library SocketIoClientDotNet has the disclaimer "This library works. There are reports of incidents where it crashes (though I was never able to reproduce them)." on its GitHub page. Other environments may have even more limited library availability.

Thus, the answer is that there may be disadvantages, but only for certain combinations of server and client platforms.

Related Topic