Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a whole site using just websockets (via socket.io and node.js, no Ajax)?

Is this possible? Has anyone tried it?

Using websockets means there are no httpheaders being exchanged (like in a Ajax request) so there is definately a boost in speed of page display, however with the sockets you are holding a connection to the server even when nothing maybe happening, is this detrimental as number of users increase?

with a connection being held between client and server, can the server still handle other clients connecting on the same port?

like image 759
Chris Avatar asked Nov 07 '11 19:11

Chris


People also ask

Which is better AJAX or WebSocket?

There are several benefits to running AJAX over WebSockets, such as: Less overhead, thus much faster (including less overhead than HTTP/2). Much easier to implement stateful services, if needed. Both AJAX and asynchronous WebSocket data can be multiplexed over the same connection.

Can Socket.IO connect to WebSocket?

Although Socket.IO indeed uses WebSocket as a transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.

How do I create a node JS WebSocket server?

Client authentication import { createServer } from 'http'; import { WebSocketServer } from 'ws'; const server = createServer(); const wss = new WebSocketServer({ noServer: true }); wss. on('connection', function connection(ws, request, client) { ws. on('message', function message(data) { console.

Which is better Socket.IO or WebSockets?

Both WebSocket vs Socket.io are popular choices in the market; let us discuss some of the major Difference Between WebSocket vs Socket.io: It provides the Connection over TCP, while Socket.io is a library to abstract the WebSocket connections. WebSocket doesn't have fallback options, while Socket.io supports fallback.


1 Answers

It is definitely possible but I have not tried it. You will get a latency boost but the bandwidth boost will not be significant. The real problem is not going to be server resources (continuously polling the server via AJAX is likely harder on the server in most ways), but that AJAX has really solved a lot of the problems (especially the ones you will run into as your scope increases) so you will be rebuilding a lot of stuff for custom use.

Unless you are actually running into a latency problem, I would suggest using standard AJAX. Or only use WebSockets for the part of you application that actually needs low latency so you are not recreating all the wheels.

Yes, being able to have multiple clients connect to one listening port simultaneously is possible and done all the time (your web server almost certainly does so on port 80 for example). Your WebSocket server will have to handle the incoming connections properly (evented, threaded, or multi-process) but it's pretty much standard fair (google "socket programming YOUR_LANGUAGE").

like image 133
kanaka Avatar answered Oct 13 '22 17:10

kanaka