HTTP headers in Websockets client API

Updated 2x Short answer: No, only the path and protocol field can be specified. Longer answer: There is no method in the JavaScript WebSockets API for specifying additional headers for the client/browser to send. The HTTP path (“GET /xyz”) and protocol header (“Sec-WebSocket-Protocol”) can be specified in the WebSocket constructor. The Sec-WebSocket-Protocol header (which is … Read more

How can I send and receive WebSocket messages on the server side?

Note: This is some explanation and pseudocode as to how to implement a very trivial server that can handle incoming and outcoming WebSocket messages as per the definitive framing format. It does not include the handshaking process. Furthermore, this answer has been made for educational purposes; it is not a full-featured implementation. Specification (RFC 6455) … Read more

In what situations would AJAX long/short polling be preferred over HTML5 WebSockets?

WebSockets is definitely the future now. Long polling is a dirty workaround to prevent creating connections for each request like AJAX does – but long polling was created when WebSockets didn’t exist. Now due to WebSockets, long polling is going away no more. WebRTC allows for peer-to-peer communication. I recommend learning WebSockets. Comparison: of different … Read more

What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

In the examples below the client is the browser and the server is the webserver hosting the website. Before you can understand these technologies, you have to understand classic HTTP web traffic first. Regular HTTP: A client requests a webpage from a server. The server calculates the response The server sends the response to the … Read more

De-serializing json format string

Your class structure is wrong. The json string contains a list of face_list not a single object. Furthermore your current face_list class does not contain any properties just two nested class definitions which will not hold any values. Correct structure: public class FaceDetect { public int age { get; set; } public int beauty { … Read more