Guest User

Untitled

a guest
Oct 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var udpSocket = new UDPSocket("imaginary-service.com");
  2.  
  3. udpSocket.onopen = function() {
  4. console.log("The UDP socket is open!");
  5. }
  6.  
  7. udpSocket.onclose = function(closeEvent) {
  8. console.log(`The UDP socket was closed. code: ${closeEvent.code}, reason: ${closeEvent.reason}`);
  9. }
  10.  
  11. udpSocket.onerror = function(errorEvent) {
  12. console.log(`A UDP socket error occurred: #{errorEvent.message}`);
  13. }
  14.  
  15. udpSocket.onmessage = function(messageEvent) {
  16. console.log(`Received UDP data: #{messageEvent.data}`);
  17. }
  18.  
  19. udpSocket.send("Hello! I hope you receive this.")
  20.  
  21. someButton.onclick {
  22. const NORMAL_CLOSURE_CODE = 1000;
  23. const NORMAL_CLOSURE_REASON = "nothing extraordinary!";
  24.  
  25. udpSocket.close(NORMAL_CLOSURE_CODE, NORMAL_CLOSURE_REASON);
  26. }
Add Comment
Please, Sign In to add comment