Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i do a client to client (browsers) socket connection?

I have been thinking about building a client to client program. But the way I want is to use the broswer to do it, helped by a server that can make that connection.

The troubles comes when I need to have an unnconected socket (or pasive) in a client, waiting for a connection.

I have been thinking about Html5 WebSockets, but it doesn't give to the client the posibility of having a pasive socket without connecting it with a TCP protocol.

I'm learning this and trying to find the way to do this. All ideas are wellcome :D.

like image 337
Angelus Avatar asked Oct 14 '22 23:10

Angelus


1 Answers

You can have a passive socket in Java applets, Flash and other browser plugins, but in general that can be problematic for public web applications.

First of all it will be difficult to get through firewalls, etc, and you'll need to depend and write code for a browser plugin that implements a socket API, and bridge it to JavaScript. If you are interested in some solutions, you may want to check out the following Stack Overflow post:

  • How can I communicate over TCP sockets from JavaScript?

The traditional approach for peer-to-peer communications between browsers is to have your server acting as a gateway for all the connections. Browsers initiate the connection (either with WebSockets or with XMLHttpRequest) and keep an active connection to the server at all times, re-establishing it if it drops. Since the server application will always find an open TCP connection to all the connected browsers, it can easily route messages to/from all clients.

like image 155
Daniel Vassallo Avatar answered Oct 16 '22 16:10

Daniel Vassallo