Reputation: 58766
Can I use webrtc to write a web server in Javascript so that someone could turn their web browser into a webserver by just visiting a URL like becomeawebserver.com (example name I just made up)?
I am just trying to learn web rtc so am trying to find out what it is capable of
I have my answer now from Svetlin Mladenov:
Webrtc cannot be used as a http server because the port cannot be specified and webrtc cannot open TCP connections. –
Upvotes: 3
Views: 2072
Reputation: 68
'Yes' - I was asking myself the same question and found +PeerServer, a Stanford senior student project. As far as I understand it, it is a javascript library which abstracts and translates webrtc data streams into HTTP.
The originating server only handles peer to peer handshakes, and from there the 'in browser' server behaves as expected from a traditional server.
I am still wrapping my head around this awesomeness, so go have a look at the project yourself. I think it recognises the limits from the previous respondents and then works around them.
Upvotes: 2
Reputation: 4427
WebRTC uses its own set of protocols (based on RTP, SCTP and others) so you cannot implement a traditional HTTP server using WebRTC. You can channel HTTP over the WebRTC Data Channel but that's obviously completely different than the traditional HTTP over TCP which is the backbone of the Internet. However if implementing and running your own protocols that are not compatible with HTTP qualifies in your eyes as a webserver, then, yes you can implement a web server using WebRTC but you cannot implement a HTTP server.
To connect to a TCP server (HTTP servers are also TCP servers) you need two things: 1. an IP address which can be obtained by DNS resolving a human readable name like becomeawebserver.com and 2. a port.
This is not so with WebRTC. Connecting to a WebRTC instance is much more complicated because WebRTC was created with peer-to-peer connections in mind so it automatically does things like NAT traversal, hole punching and so on. All of this means that a WebRTC instance doesn't have just a single IP address but a multitude of IP addresses. WebRTC automatically searches for the best one to connect to.
For a WebRTC connection to be established a third party (in the form of a signaling server) is required. So if you want for a client to be able to input just a human readable name (like becomeawebserver.com) and connect to a browser-turned-server then you have to implement the resolving yourself (DNS is not suitable because webrtc instances have many addresses which are not known in advance and webrtc binds to a random ephemeral port) and do the signaling between the two instances in order to connect them together and then the rest of the communication can be performed directly througth the WebRTC Data Channel.
So to sum up: WebRTC uses its own protocols so you have to implement and use your own version of HTTP, DNS and so one. If that qualifies as a webserver for you then, yes, you can implement a webserver using WebRTC.
Upvotes: 2