Reputation: 31
I want to send an UDP package to my UDP server in browser. I heard that HTML5 or WEBRTC can do something, but I don't know how.
Can someone help me?
Upvotes: 2
Views: 7340
Reputation: 7303
You could either write a chrome extension (app) which would give you access to https://developer.chrome.com/apps/sockets_udp ("sockets": {...}
in your manifest.json).
Or, as far as WebRTC goes:
var pc = new webkitRTCPeerConnection(
{ "iceServers": [{ "url": "stun:localhost:1234" }] }
);
pc.createOffer(function (sessionDescription) {
pc.setLocalDescription(sessionDescription);
}, function(error) {
alert(error);
}, { 'mandatory': { 'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true } });
You'd then able to get the UDP packets on localhost:1234 via:
$port = 1234
t = Thread.start do
server = UDPSocket.open
server.bind(nil, $port)
a = server.recvfrom(12364)
puts server.send "ping", 0, a[1][2], a[1][1]
end
t.join
Upvotes: 3