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)
...into this?
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With