Angelus
Angelus

Reputation: 53

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.

Upvotes: 5

Views: 2873

Answers (2)

Rasjid Wilcox
Rasjid Wilcox

Reputation: 711

As Daniel says, you are going to have a very hard time trying to do true peer-to-peer (a la Skype etc) in the browser, and it is certainly not possible without the use of plugins. And even Skype etc rely on falling back to a server acting as a gateway when a direct connection cannot be established (due to firewalls etc).

So you really need to have a gateway server regardless, and that there are a number of options. Try searching here for 'comet'. Some options that I have played with include Orbited (http://orbited.org/) and Hookbox (http://hookbox.org/) but there are many others.

Upvotes: 0

Daniel Vassallo
Daniel Vassallo

Reputation: 344251

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:

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.

Upvotes: 4

Related Questions