Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix indentation and some other improvements
- Loading branch information
1 parent
15cbe21
commit eb60b07
Showing
2 changed files
with
15 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,17 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>WebSocket Client</title> | ||
<meta charset="utf-8"> | ||
<title>WebSocket Client Demo</title> | ||
</head> | ||
<body> | ||
<h1>WebSocket Client</h1> | ||
<p>Open your web console to see the response!</p> | ||
<form> | ||
<label for="message">Send a message</label> | ||
<input id="message" name="message" type="text"> | ||
<button id="send" name="send">Send</button> | ||
</form> | ||
|
||
<!-- latest jQuery --> | ||
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | ||
|
||
<script> | ||
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'); | ||
var message = document.getElementById('message').value; | ||
|
||
sendBtn.addEventListener('click', function(ev) { | ||
ws.sendMessage(message); | ||
ev.preventDefault(); | ||
}); | ||
|
||
/* | ||
$('#send').on('click', function(ev) { | ||
ws.sendMessage( $('#message').val() ); | ||
ev.preventDefault(); | ||
}); | ||
*/ | ||
</script> | ||
<h1>WebSocket Client</h1> | ||
<p>Open the JavaScript console to see the response!</p> | ||
<form> | ||
<label for="message">Send a message</label> | ||
<input id="message" name="message" type="text"> | ||
<button id="send" name="send">Send</button> | ||
</form> | ||
<script src="ws_client.js"></script> | ||
</body> | ||
</html> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters