How to Use Sockets in JavaScript\HTML? [closed]

How to Use Sockets in JavaScript/HTML? There is no facility to use general-purpose sockets in JS or HTML. It would be a security disaster, for one. There is WebSocket in HTML5. The client side is fairly trivial: socket= new WebSocket(‘ws://www.example.com:8000/somesocket’); socket.onopen= function() { socket.send(‘hello’); }; socket.onmessage= function(s) { alert(‘got reply ‘+s); }; You will need … Read more

Accessing HttpSession from HttpServletRequest in a Web Socket @ServerEndpoint

Update (November 2016): The information provided in this answer is for the JSR356 spec, individual implementations of the spec may vary outside of this information. Other suggestions found in comments and other answers are all implementation specific behaviors outside of the JSR356 spec. If the suggestions in here are causing you problems, upgrade your various … Read more

Creating a “Hello World” WebSocket example

WebSockets is protocol that relies on TCP streamed connection. Although WebSockets is Message based protocol. If you want to implement your own protocol then I recommend to use latest and stable specification (for 18/04/12) RFC 6455. This specification contains all necessary information regarding handshake and framing. As well most of description on scenarios of behaving … Read more

WebSockets and Apache proxy: how to configure mod_proxy_wstunnel?

I finally managed to do it, thanks to this topic. TODO: 1) Have Apache 2.4 installed (doesn’t work with 2.2), and do: a2enmod proxy a2enmod proxy_http a2enmod proxy_wstunnel 2) Have nodejs running on port 3001 3) Do this in the Apache config <VirtualHost *:80> ServerName example.com RewriteEngine On RewriteCond %{REQUEST_URI} ^/socket.io [NC] RewriteCond %{QUERY_STRING} transport=websocket … Read more

WebSockets protocol vs HTTP

1) Why is the WebSockets protocol better? WebSockets is better for situations that involve low-latency communication especially for low latency for client to server messages. For server to client data you can get fairly low latency using long-held connections and chunked transfer. However, this doesn’t help with client to server latency which requires a new … Read more

How to make cross domain request [duplicate]

You can make cross domain requests using the XMLHttpRequest object. This is done using something called “Cross Origin Resource Sharing”. See: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing Very simply put, when the request is made to the server the server can respond with a Access-Control-Allow-Origin header which will either allow or deny the request. The browser needs to check this … Read more

node.js, socket.io with SSL

Use a secure URL for your initial connection, i.e. instead of “http://” use “https://”. If the WebSocket transport is chosen, then Socket.IO should automatically use “wss://” (SSL) for the WebSocket connection too. Update: You can also try creating the connection using the ‘secure’ option: var socket = io.connect(‘https://localhost’, {secure: true});