So I tried all solutions around there:
https://github.com/ibdknox/socket.io-netty
https://github.com/benkay/java-socket.io.client
https://github.com/TooTallNate/Java-WebSocket
https://github.com/Ovea/Socket.IO-Java
And probably others. Couldn't get any of them working the way I wanted
(some of them are buggy with newer versions/drafts of socket.io or
websocket, jetty servlet sucks, etc).
So I made the simplest solution I could thought of: a simple tcp
socket, wich may work for every language that have socket api
I wanted to create a communication channel between browser and my Java
backend so this is how it works:
- Create a Node.JS TCP Server
- Java connects to node.js and send a string with the namespace name
it wants
- node.js then create a socket.io server with the namespace and start
forwarding all data from socket to all socket.io clients connected to
that namespace
A better approach would be replace sockets with something faster (like
http://www.zeromq.org/ - https://github.com/EhevuTov/netPeek)
Codes:
- node.js server: http://pastebin.com/Fv9g7sbF
- java code to send messages: http://pastebin.com/aNjuJjHa
- html sample code: http://pastebin.com/uazEgybE
* make sure to use the last socket.io (v0.8.7)
When I started this I had no js/nodejs/socket.io experience so as you
can see the server code is really messy and probably highly non
optimized.
Feel free to share opinions, sugestions, bugs and improvements
Thanks
On Nov 24, 8:49 am, David Benko <davidbe...@gmail.com> wrote:
> I was looking for a solution to integrate a backend that I already
> have made in Java with socket.io because its great browser
> compatibility and I didnt want to rewrite all server in javascript.
>
> So I tried all solutions around there:
>
>
> And probably others. Couldn't get any of them working the way I wanted
> (some of them are buggy with newer versions/drafts of socket.io or
> websocket, jetty servlet sucks, etc).
>
> So I made the simplest solution I could thought of: a simple tcp
> socket, wich may work for every language that have socket api
>
> I wanted to create a communication channel between browser and my Java
> backend so this is how it works:
>
> - Create a Node.JS TCP Server
> - Java connects to node.js and send a string with the namespace name
> it wants
> - node.js then create a socket.io server with the namespace and start
> forwarding all data from socket to all socket.io clients connected to
> that namespace
>
> A better approach would be replace sockets with something faster (likehttp://www.zeromq.org/-https://github.com/EhevuTov/netPeek)