Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a websocket server using JavaScript (client-side)? [duplicate]

I have just seen that the Websockets reference MDN article says

WebSocketServer

Used for opening a new WebSocket server. Required information is (port, origin, location).

Then, does it mean I can create a websocket server client-side?

If that's it, does it mean I can turn this... (each arrow is a websocket connection)

enter image description here

...into this?

enter image description here

But, do browsers have the power of doing that without any router/firewall configuration?

And how can I use it? The WebSocketServer link is broken. And I have tried searching it but I haven't found anything.

like image 208
Oriol Avatar asked Aug 10 '13 01:08

Oriol


People also ask

How do I run a WebSocket server in JavaScript?

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.

Can a WebSocket have multiple clients?

A server can open WebSocket connections with multiple clients—even multiple connections with the same client. It can then message one, some, or all of these clients. Practically, this means multiple people can connect to our chat app, and we can message some of them at a time.

How do I create a WebSocket server?

Creating a WebSocket objectThe URL to which to connect; this should be the URL to which the WebSocket server will respond. This should use the URL scheme wss:// , although some software may allow you to use the insecure ws:// for local connections. Either a single protocol string or an array of protocol strings.

Does WebSocket use JavaScript?

JavaScript is important to WebSocket only in browsers because the browsers have implemented the WebSocket API (See RFC 6455) in JavaScript. So if you want to access WebSocket from within an HTML5 page, you need to write JavaScript. However, you can also do WebSocket in a client in Java by using a Java Applet.


1 Answers

It looks like WebSocketServer is something currently under development by Mozilla without much support or anything of the like. I searched through some of their repositories and couldn't find any references, except for in some testing code for normal WebSockets.

If what you're looking for is some form of P2P WebSockets, I don't think that's possible without some work right now. You need, as others have said, a server endpoint for the connection, something that is most popularly implemented in languages like Python and node.js

like image 104
redct Avatar answered Oct 15 '22 02:10

redct