-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.html
65 lines (56 loc) · 1.58 KB
/
client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html>
<head>
<script type="text/javascript">
var ws = null;
function login(){
ws = new WebSocket('ws://localhost:9999');
ws.onclose = function () {
alert('WebSocket closed or not available');
};
ws.onmessage = function (event) {
alert('Data received: ' + event.data);
};
ws.onopen = function () {
var version = {"type":"VersionMessage","fields":{"version":"NetLogo 5.0RC2"}}
var handshake = {"type":"HandshakeFromClient",
"fields":{"userId":document.getElementById('message').value,"clientType":"COMPUTER"}}
var enter = {"type":"EnterMessage"}
send(version);
send(handshake);
send(enter);
ws.onmessage = function (event) {
//alert('Data received: ' + event.data);
};
};
}
function pressButton(b){
var message = {
"type": "ActivityCommand",
"fields": {
"tag": b,
"content": {
"type": "Boolean",
"value": false
}
}
};
send(message);
}
function send(msg) {
//alert("about to send: " + JSON.stringify(msg));
ws.send(JSON.stringify(msg))
}
</script>
</head>
<body>
<form>
Username:
<input type="text" name="message" id="message" value="josh"/>
<input type="button" value="Login" onclick="login()" />
<input type="button" value="up" onclick="pressButton('up')" />
<input type="button" value="down" onclick="pressButton('down')" />
<input type="button" value="left" onclick="pressButton('left')" />
<input type="button" value="right" onclick="pressButton('right')" />
</form>
</body>
</html>