Why can we not have UDP connection between a browser and a server? Why is TCP connection possible (via WebSockets) and UDP not?
Asked
Active
Viewed 8,717 times
7
-
Because websockets are built on top of TCP. – Marc B Jul 15 '13 at 15:49
-
chrome packaged apps have access to an API for UDP io. – dandavis Jul 15 '13 at 15:55
-
Can you explain more so I can google it? What is that API? Are you talking about webRTC? – C graphics Sep 17 '13 at 16:40
2 Answers
5
HTML5 does not allow arbitrary TCP connections.
Instead, web sockets is a special new protocol built on on TCP that allows bidirectional communication.
Similarly, WebRTC is a special new protocol built on UDP that allows peer-to-peer communication.
Allowing arbitrary socket connections would be a major security hole.

SLaks
- 868,454
- 176
- 1,908
- 1,964
-
-
@Cgraphics: It wouldn't make sense to allow UDP web sockets. Web sockets rely on properties of TCP like ordering and guaranteed delivery. – SLaks Jul 15 '13 at 15:52
-
3
You can get access to UDP using WebRTC, which is available in the latest versions of Chrome and Firefox. This lets you do direct browser - browser connections without needing to go via the server, amongst other things.

rjmunro
- 27,203
- 20
- 110
- 132
-
Nice can we make UDP connections between a browser to a server too? I guess right? – C graphics Jul 15 '13 at 15:52
-
1actually, RTC still needs a server to handshake, which is not clear in from the text shown... – dandavis Jul 15 '13 at 15:56
-
I believe it is possible, yes. You will need to have a server side implementation of the WebRTC protocols. I have heard of such things being talked about, but I don't know of any actual implementation. – rjmunro Jul 15 '13 at 15:57
-
1yup, webRTC uses ICE http://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment to negotiate a the connection, which can be implemented on a server side. using libjingle https://developers.google.com/talk/libjingle/ - you *should* be able to create a client/server udp connection though it might be quite challenging. – benjaminbenben Jul 15 '13 at 16:00