32 lines
762 B
HTML
32 lines
762 B
HTML
|
<!doctype html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
<title>Web socket test</title>
|
||
|
<script type="text/javascript">
|
||
|
var ws = new WebSocket('ws://localhost:1234', 'echo-protocol');
|
||
|
|
||
|
function sendMessage(){
|
||
|
var message = document.getElementById('message').value;
|
||
|
ws.send(message);
|
||
|
}
|
||
|
|
||
|
ws.addEventListener("message", function(e) {
|
||
|
// The data is simply the message that we're sending back
|
||
|
var msg = e.data;
|
||
|
|
||
|
// Append the message
|
||
|
document.getElementById('chatlog').innerHTML += '<br>' + msg;
|
||
|
});
|
||
|
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div>Send data:</div>
|
||
|
<textarea id='message'>This is the sent text</textarea>
|
||
|
<input type='button' value='send message' onclick='sendMessage()'/>
|
||
|
<div>Received from server:</div>
|
||
|
<div id='chatlog'></div>
|
||
|
</body>
|
||
|
</html>
|