hapablap
hapablap

Reputation: 51

Java WebSocket server with HTML5 client - is socket.io necessary?

I want to create a HTML5 MMORPG game. For this I need low latency communication between client and server. Because of choosing HTML5 als the client technology, it is clear that I will develop the game in JavaScript. I found out that there is an engine called socket.io which makes communication between client and server possible.

But I don't want to write the server in JavaScript. One reason is that I don't want the code to be open, to prevent cheating. My choice was to use C++ or Java for the server. It seemed for me that it is easier to use Java (I am more familiar with C#, I guess that will help me here).

My problem now is to combine Java WebSocket (server) and socket.io (client). But... I've created a test application with Java WebSocket with an HTML5 client (without socket.io!) and the communication worked. So I have a few questions:

  1. Do I need socket.io? If yes, why? What is the difference between using the default code, created with an Java WebSocket default project?

  2. If I need socket.io, how can I combine socket.io with Java WebSockets? I found a article (https://oneminutedistraction.wordpress.com/2013/08/12/marrying-socket-io-client-with-java-ee-7s-websocket/) about it, but it didn't work. I really can't tell why. I found out, that socket.io tries to connect to webservice-url/socket.io by default and you can change that. I changed it and got now more errors in the JavaScript console. But I don't get the event triggert for connection established. So I gues, it is not working.

  3. (optional question) Can I use only socket.io and make my server code safe? So that no one can read the code? I guess not? Or is there any alternative way to solve my problem? I am still searching for the technologies which fit my situation best.

Upvotes: 0

Views: 910

Answers (1)

Dhruv Batheja
Dhruv Batheja

Reputation: 2350

Socket.io enables real-time, bi-directional communication between web clients and server. They have already fixed issues that you have not yet faced. The node implementation of their server is very easy to understand. Also there are several clients implementations available: Android-client, Java-Client

Try using their example chat application to get yourself ramped up :)

Upvotes: 1

Related Questions