Websockets, continued
information about session
import java.io.IOException; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; @ServerEndpoint("/demo4") public class WebSocketDemo4 { @OnOpen public void greeting(Session session) { try { System.out.println("got new connection:" + session.getId()); long timeout = session.getMaxIdleTimeout(); boolean isSecure = session.isSecure(); int textMessageBufferSize = session.getMaxTextMessageBufferSize(); session.getBasicRemote().sendText( "Your idle timeout limit is:" + timeout); session.getBasicRemote().sendText( "Your session is " + (isSecure ? "" : "not") + " secure"); session.getBasicRemote().sendText( "Your max text message size is: " + textMessageBufferSize); } catch (IOException e) { e.printStackTrace(); } } }
Pushing your web sockets application to heroku
- You will need an embedded Tomcat websocket dependency
- The embedded Tomcat 7 I had in my pom did not understand the websocket, so I had to upgrade to latest 8
- Heroku works on HTTPS, therefore both JQuery and your web sockets will have to work on SSL, this simply means add the s for http and ws making them https and wss in your html files.
- Once your application is on Heroku, localhost:8080 will not work anymore, so your html files will need to be modified
Full code is here: https://github.com/gnurmatova/WebSockets
Chatroom on heroku: https://unhsockets.herokuapp.com/demo3.html