Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var udpSocket = new UDPSocket("imaginary-service.com");
- udpSocket.onopen = function() {
- console.log("The UDP socket is open!");
- }
- udpSocket.onclose = function(closeEvent) {
- console.log(`The UDP socket was closed. code: ${closeEvent.code}, reason: ${closeEvent.reason}`);
- }
- udpSocket.onerror = function(errorEvent) {
- console.log(`A UDP socket error occurred: #{errorEvent.message}`);
- }
- udpSocket.onmessage = function(messageEvent) {
- console.log(`Received UDP data: #{messageEvent.data}`);
- }
- udpSocket.send("Hello! I hope you receive this.")
- someButton.onclick {
- const NORMAL_CLOSURE_CODE = 1000;
- const NORMAL_CLOSURE_REASON = "nothing extraordinary!";
- udpSocket.close(NORMAL_CLOSURE_CODE, NORMAL_CLOSURE_REASON);
- }
Add Comment
Please, Sign In to add comment