5

I don't quite know how to search this in google:

  • "client to client websocket connections"
  • "browser to browser websockets"
  • "websockets without a server"

Haha, is there a way for someone on a webpage in the browser to communicate directly to another person on a web page in the browser, without touching the server?

I am very familiar with socket.io, but that requires all clients emit messages to the server, which can broadcast them to the other connected clients. I am not familiar with the details of web sockets though, so maybe there's a way to communicate without sending messages through the server.

Is this possible? I just want to know the scope of web socket functionality, the limits you can take them too, etc.

Lance
  • 75,200
  • 93
  • 289
  • 503
  • I don't believe this is possible. Not without having one of the client's behave like a server at least. – Some Guy Nov 05 '11 at 06:32
  • 1
    can a client behave like a server? – Lance Nov 05 '11 at 06:43
  • If this is a personal project and you just want to do this to connect to your own computer or something, yes, by setting up a local server (like XAMPP) and getting a static IP Address (or using DynDNS) – Some Guy Nov 05 '11 at 08:09
  • Maybe this works? http://stackoverflow.com/questions/13162470/communication-among-two-to-client-side-sessions-in-javascript – Yigit Pilevne Jan 21 '13 at 11:05
  • possible duplicate of [How can i do a client to client (browsers) socket connection?](http://stackoverflow.com/questions/3864550/how-can-i-do-a-client-to-client-browsers-socket-connection) – doppelgreener Jul 17 '14 at 03:45

5 Answers5

11

Not Web Sockets, but four years later and now we've got browser-to-browser communication!
http://www.webrtc.org/

There are JS libraries built around it to make it easier (e.g. https://simplewebrtc.com/). However, it does still require a server to orchestrate connections.

I know this question is ancient, but it showed up in Google when I searched so it likely will for others!

Matt Thomas
  • 5,279
  • 4
  • 27
  • 59
4

This is not possible, you have to have the server in the middle.

alessioalex
  • 62,577
  • 16
  • 155
  • 122
1

For an application to accept connections, it has to have a server port open and listening for incoming requests. You cannot have a server socket exposed from a browser. I dont know if you can expose a server socket from within an applet. But even if you could, you would need to know the IP address of the other client for establishing a peer to peer connection.

Drona
  • 6,886
  • 1
  • 29
  • 35
0

The moment you have a client listening for websockets (which you have to do in other to communicate), it becomes a server.

Asier
  • 1
0

Well, technically when you broadcast, the client emits to the server, the server broadcasts to everyone. I don't think with the current architecture of the web peer to peer connections like this is possible.

But it is possible that a client send a message to server specifying another client ID, and the server sending it to the other clients using sessions.

Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115