2013-09-01 22:54:51 +02:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Web socket test</title>
|
|
|
|
<script type="text/javascript">
|
2013-09-02 20:33:43 +02:00
|
|
|
|
|
|
|
var ws;
|
2013-09-01 22:54:51 +02:00
|
|
|
|
|
|
|
function sendMessage(){
|
|
|
|
var message = document.getElementById('message').value;
|
|
|
|
ws.send(message);
|
|
|
|
}
|
|
|
|
|
2013-09-02 20:33:43 +02:00
|
|
|
function connection() {
|
|
|
|
ws = new WebSocket('ws://localhost:1234', 'echo-protocol');
|
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('connect_button').style.display = 'none';
|
|
|
|
}
|
2013-09-01 22:54:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
</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>
|
2013-09-02 20:33:43 +02:00
|
|
|
<input id='connect_button' type='button' value='Connect to server using websockets' onclick='connection()'/>
|
2013-09-01 22:54:51 +02:00
|
|
|
</body>
|
|
|
|
</html>
|