Javascript examples for Language Basics:WebSocket
Catch error in WebSocket constructor instantiation
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w . jav a2 s. c o m host='localhost'; port=100; try { ws = new WebSocket('ws://'+ host + ':' + port + '/'); } catch (err) { console.log('This never prints'); } ws.onerror = function (error) { console.log(error); }; } </script> </head> <body> </body> </html>