EzDevInfo.com

websocket interview questions

Top websocket frequently asked interview questions

Best Ruby on Rails WebSocket tool [closed]

I started project in Rails 3 and I need to add notifications(like Facebook one). Best way would be using WebSocket for support devices like iPad, but I can't find any good tools to easy implement it in Rails. I found Pusherapp, but they prices are overwhelming, and also I don't think that providing my data to third party company would be wise. So things needed:

  • Open Source
  • Some kind of channels support
  • Helpers for Rails(and working with Rails 3)

Source: (StackOverflow)

Differences between socket.io and websockets

What are the differences between socket.io and websockets in node.js?
Are they both server push technologies? The only differences I felt was,

  1. socket.io allowed me to send/emit messages by specifying an event name.
  2. In the case of socket.io a message from server will reach on all clients, but for the same in websockets I was forced to keep an array of all connections and loop through it to send messages to all clients.

Also, I wonder why web inspectors(like Chrome/firebug/fiddler) are unable to catch these messages(from socket.io/websocket) from server?

Please clarify this.. Thanks.


Source: (StackOverflow)

Advertisements

Do I need a server to use HTML5's WebSockets?

When using WebSockets, will I need to write server code? In other words, will the JavaScript in my client application need to connect to a specialized server, or will my existing Apache server work to support this?


Source: (StackOverflow)

Debugging WebSocket in Google Chrome

Is there a way, or an extension, that lets me watch the "traffic" going through a WebSocket? For debugging purposes I'd like to see the client and server requests/responses.


Source: (StackOverflow)

Standalone C or C++ websocket server library [closed]

I'd like to create a websocket server within one of my C++ programs.

Do any standalone C or C++ libraries exist for creating websockets or is the only option to get the WebKit or V8 sources and extract their implementation?


Source: (StackOverflow)

Closing WebSocket correctly (HTML5, Javascript)

I am playing around with HTML5 WebSockets. I was wondering, how do I close the connection gracefully? Like, what happens if user refreshes the page, or just closes the browser?

There is a weird behavior when a user just refresh the page without calling websocket.close() - when they return after the refresh it will hit the websocket.onclose event.


Source: (StackOverflow)

What is the fundamental difference between WebSockets and pure TCP?

I've read about WebSockets and I wonder why browser couldn't simply open trivial TCP connection and communicate with server like any other desktop application. And why this communication is possible via websockets?


Source: (StackOverflow)

Why use AJAX when WebSockets is available?

I've been using WebSockets for a while now, I have chosen to create an Agile project management tool for my final year project at University utilizing Node server and WebSockets. I found using WebSockets provided a 624% increase in the number of requests per second my application could process.

However since starting the project I've read of security loopholes, and some browsers choosing to disable WebSockets by default..

This leads me to the question:

Why use AJAX when WebSockets seems to do such a great job of lowering latency and resource overhead, is there anything that AJAX does better than WebSockets?


Source: (StackOverflow)

websocket api to replace rest api?

I have an app whose primary function works in real time, through websockets or long polling. However most of the site is written in a RESTful fashion, which is nice for apps and other clients in the future. However I'm thinking about transitioning to a websocket api for all site functions, away from rest. That would make it easier for me to integrate real time features into all parts of the site. Would this make it more difficult to build apps or mobile clients?

Thanks.

Edit: found that some people are already doing stuff like this: https://github.com/socketstream/socketstream


Source: (StackOverflow)

How do I run Node.js on port 80?

My aim is to run Node.js on port 80. This is because I am finding node.js is being blocked from certain networks which do not allow traffic from any other port.

It appears that the best way to do this is by proxying Apache through Node.js. I have tried using node-http-proxy to do this but I have not had any luck.

The code I am using is here:

var util = require('util'),
    http = require('http'),
    httpProxy = require('http-proxy');

httpProxy.createServer(9000, 'localhost').listen(80);

http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);

But I keep getting the error "Address in use" for port 80. I must be doing something wrong.

How do I proxy Apache through node.js using node-http-proxy? Will this enable me to run node.js on port 80? And is node-http-proxy the best way to achieve this?

Thank you.


Source: (StackOverflow)

Does HTTP/2 make websockets obsolete?

I'm learning about HTTP/2 protocol. It's a binary protocol with small message frames. It allows stream multiplexing over single TCP connection. Conceptually it seems very similar to WebSockets.

Are there plans to obsolete websockets and replace them with some kind of headerless HTTP/2 requests and server-initiated push messages? Or will WebSockets complement HTTP/2?


Source: (StackOverflow)

How can I get the sha1 hash of a string in node.js?

I'm trying to create a websocket server written in node.js

To get the server to work I need to get the SHA1 hash of a string.

What I have to do is explained in Section 5.2.2 page 35 of the docs.

NOTE: As an example, if the value of the "Sec-WebSocket-Key" header in the client's handshake were "dGhlIHNhbXBsZSBub25jZQ==", the server would append thestring "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-C5AB0DC85B11". The server would then take the SHA-1 hash of this string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value is then base64-encoded, to give the value "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned in the "Sec-WebSocket-Accept" header.


Source: (StackOverflow)

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

  • How can I send and receive messages on the server side using WebSocket, as per the protocol?

  • Why do I get seemingly random bytes at the server when I send data from the browser to the server? It the data encoded somehow?

  • How does the framing work in both the server → client and client → server directions?


Source: (StackOverflow)

Difference between socket and websocket?

I'm building web app that needs to communicate with another application using socket connections. This is new territory for me, so want to be sure that sockets are different than websockets. It seems like they're only conceptually similar.

Asking because initially I'd planned on using Django as the foundation for my project, but in the SO post I linked to above it's made very clear that websockets aren't possible (or at least not reliable, even with something like django-websockets) using the preferred Django setup (Apache with mod_wsgi). Yet I've found other posts that casually import Python's socket module for something as simple as grabbing the server's hostname.

So:

  • Are they really different?
  • Is there any reason not to use Django for a project that relies on establishing socket connections with an outside server?

Source: (StackOverflow)

node.js multi room chat example

I'm looking for a websocket/node.js chat implementation which supports multiple rooms.

I'm also going to write an app which needs multiple rooms or servers, and I'm just looking for some code samples of how people do it.

Thanks.

I know there's a service http://pusherapp.com which provides this service, but I'm looking for an open source example.


Source: (StackOverflow)