Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

websocket

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?

like image 576
cometta Avatar asked Oct 07 '09 07:10

cometta


People also ask

How do I create a WebSocket server?

Creating a websocket server import express from "express"; import startup from "./lib/startup"; import api from "./api/index"; import middleware from "./middleware/index"; import logger from "./lib/logger"; import websockets from './websockets'; startup() . then(() => { const app = express(); const port = process.

Why you should not use WebSocket?

Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.

How many WebSockets are in a server?

By default, a single server can handle 65,536 socket connections just because it's the max number of TCP ports available.

How do I access WebSockets?

To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.


6 Answers

The server has to support web sockets. After a first handshake in HTTP, the server and the client open a socket connection. The server must be able to understand and accept this handshake.

In my last project we run quite successfully web socket connections using the last Jetty version.

27/02/2014: Now I'm also implementing websockets under .net with XSockets.net and works like a charm, you don't even need a web server (self hosting). The WebSocket implementation of ASP.NET works also quite good.

like image 138
Rafa Avatar answered Oct 03 '22 05:10

Rafa


Yes,you need to write server code.

I recommend another web socket server based on php: ratchet. And this link is benchmarking webSocket servers between ratchet and sockJS.

Complete list of client & server side codes and browsers support please check this link

like image 45
ShahRokh Avatar answered Oct 03 '22 06:10

ShahRokh


Of course you need a WebSocket server. But there are many free websocket server in different language, like jWebSocket in Java and SuperWebSocket in .NET, you can use them directly.

like image 29
Kerry Jiang Avatar answered Oct 03 '22 05:10

Kerry Jiang


There are some plugins currently being developed on google code for Apache...

By definition websockets like normal sockets are client-server so yes, you need a server. However there is an alternative to waiting for Apache plugins.

I am using a hosted server http://www.achex.ca. Its free and you have tutorials in javascript on how to use the server. A good start for websockets development.

The server is basically a message router and you can connect to it and use it as a meeting point for all your websocket clients.

Short Answer: Yes, You need a specialized server, Apache does not come with websockets.
OR
The alternative, check out www.achex.ca.

like image 22
AlexC_JEng Avatar answered Oct 03 '22 06:10

AlexC_JEng


In such a situation the role of server comes when :

In HTML 5,WebSocket like a fone(2-way comm.) not walky-talky. http protocol upgraded to websocket protocol.(wss:// from ws://) SERVER should be able to open duplex channel and hence AGREE with duplex communication.

Please go through this link : http://www.html5rocks.com/en/tutorials/websockets/basics/

If using php please look at RATCHET.

Thanks.

like image 45
Sid Avatar answered Oct 03 '22 05:10

Sid


The Perl Mojolicious server supports web sockets, and implementations can be only a few lines long.

Node.js has several WebSocket libraries but details of the latest, greatest, most supportive of the latest spec vary, so choose carefully.

Apache Active MQ is also worth a look, along with the stomp protocol it implements.

like image 32
Lee Goddard Avatar answered Oct 03 '22 07:10

Lee Goddard