I want to use the Websocket protocol to let Particle communicate with a JavaEE server. I’m looking for a library with example, with let Particle connect to server (onOpen), receive message (onMessage) and some function which let Photon send message. How Can I do ? I hope to found a solution, because it’ll be very powerful to work with this solution.
Is there are reason you need to use WebSocket? That’s a great solution if you need a full-duplex data channel between a web browser and a server, but it adds a huge layer of complexity you don’t need with the Particle Photon.
Assuming you have control over the Java EE server as well as the Photon, instead of using WebSocket you use a normal Java TCP ServerSocket and Socket on the Java EE server side and TCPClient on the Photon side. No additional libraries are needed on either side.
Basically, WebSocket is a layer to allow a browser to make a TCP-style connection with a web server, but with Java EE and Particle you don’t need that layer because both sides natively speak TCP.
Thank you for your reply. Well websocket are, as you said, a very good solution for full-duplex and persistance connection between an unique server and multiple client. If Particle has to send and receive data, it should be at the same time a TCP Server and a TCP Client. In addition, if the Particle should work as a TCP Server, some problems with NAT and not unique IP pubblic address will happen. In the meantime, I was able to found out this library:
what do you think about? It’s seems very easy. The only question which it’s in my mind is this: what type of host should I put? My JavaEE has this url: ws://ip:8080/WebsocketProject/example.