Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add client implementation (W3C compliant)

  • Loading branch information...
commit 8dfaed210de7289163b70299b2c9ea393bff8089 1 parent eb60b07
@simonewebdesign authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 ws_client.js
View
33 ws_client.js
@@ -0,0 +1,33 @@
+(function(){
+
+ var ws = new WebSocket("ws://localhost:1337");
+
+ ws.onopen = function(ev) {
+ console.log('Connection opened.');
+ }
+
+ ws.onmessage = function(ev) {
+ console.log('Response from server: ' + ev.data);
+ }
+
+ ws.onclose = function(ev) {
+ console.log('Connection closed.');
+ }
+
+ ws.onerror = function(ev) {
+ console.log('An error occurred. Sorry for that.');
+ }
+
+ WebSocket.prototype.sendMessage = function(msg) {
+ this.send(msg);
+ console.log('Message sent: ' + msg);
+ }
+
+ var sendBtn = document.getElementById('send');
+ sendBtn.addEventListener('click', function(ev) {
+ var message = document.getElementById('message').value;
+ ws.sendMessage(message);
+ ev.preventDefault();
+ });
+
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.