9

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.

Oriol
  • 274,082
  • 63
  • 437
  • 513
  • http://nodejs.org/ You can do websockets with node which is javascript. – Sir Aug 10 '13 at 01:41
  • @Dave No, I want it client-side. – Oriol Aug 10 '13 at 01:48
  • do you mean you want your pc to be the server like your localhost ? – Sir Aug 10 '13 at 01:50
  • @Dave But MDN page suggests that there is some implementation client-side of a WebSocket server. And no, I don't want my PC to be the server. I want (well, I don't, it's just academical) the browsers which connect to my server to be able to connect one to each other using websockets. – Oriol Aug 10 '13 at 01:50
  • You need server side which connects clients together. – Sir Aug 10 '13 at 01:53
  • @Dave But if it can't be done client-side, why does https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference suggest that there is a client-side interface `WebSocketServer`? – Oriol Aug 10 '13 at 02:10
  • Where does it say it is client side server? which doesn't make sense, its either client side or server side, client side can't also be server side. – Sir Aug 10 '13 at 02:12
  • @Dave It doesn't say it explicitly, that's why I say *suggests*. But next to `WebSockets` interface (which is client-side), it says `WebSocketServer`, so I guess that's another client-side interface. And when I say a client-side server I mean that clients' browsers (client-side) listen to connections from other browsers, so they act like a server – Oriol Aug 10 '13 at 02:22
  • i think you're misreading something or they worded it badly. – Sir Aug 10 '13 at 03:05
  • See http://stackoverflow.com/questions/4118272/do-websockets-allow-for-p2p-browser-to-browser-communication and http://stackoverflow.com/questions/7022383/how-to-make-a-browser-to-browser-peer-to-peer-connection. This also looks interesting: http://peerjs.com/ – bfavaretto Aug 10 '13 at 03:43
  • Also keep in mind that MDN is a wiki, and the page you linked to is a draft. – bfavaretto Aug 10 '13 at 16:02
  • I came here expecting to find the same answers. Unfortunately Mozilla seems to be the only one innovating here. Two Mozilla drafted specs I really want to see standardized is this & TCPSocket: https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket – micwallace Jun 12 '15 at 12:04

2 Answers2

3

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

redct
  • 884
  • 1
  • 6
  • 8
1

You need to have a server-side endpoint for the WebSocket. A web socket is an open connection between the server and a client - how could you possible achieve this without a server? I don't quite understand what you are trying to convey with the diagrams, but you need to set up special configurations on the server-side to create a web socket resource like this: ws://example.com/resource so you can't arbitrarily create websockets between two clients and such.

hesson
  • 1,812
  • 4
  • 23
  • 35
  • Well, I was surprised that it could be done client-side. But if it can't be done, why does MDN page suggest that there is some implementation client-side of a WebSocket server? – Oriol Aug 10 '13 at 01:55
  • @Oriol You use WebSocket using JavaScript on the client-side to connect to a web-socket resource on the server. – hesson Aug 10 '13 at 02:00
  • Please read https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference . You are talking about `WebSocket` interface (*The primary interface for connecting to a WebSocket server and then sending and receiving data on the connection*). I'm talking about `WebSocketServer` interface (*Used for opening a new WebSocket server*) – Oriol Aug 10 '13 at 02:02
  • @Oriol There doesn't seem to be any documentation on `WebSocketServer` anywhere (even W3C) aside from that brief description on the MDN link you provided, so I'm inclined to believe it's still a technology in development by Mozilla. As far as I can see, it's not a part of ECMAScript. – hesson Aug 10 '13 at 02:36
  • I think WebSocketServer may be used in nodejs, but I am sure it's not used on client-side web development. – hesson Aug 10 '13 at 02:51
  • You might want to look into WebRTC. You can establish local P2P connections between browsers, but over the internet a nameserver is still required. – Dominic Cerisano Jul 21 '16 at 20:22