-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_client.html
More file actions
56 lines (47 loc) · 1.64 KB
/
Copy pathchat_client.html
File metadata and controls
56 lines (47 loc) · 1.64 KB
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Chat Client</title>
<script type="text/javascript" src="websocketremotefunctioncaller.js"></script>
<script type="text/javascript">
var rfc = new WebSocketRemoteFunctionCaller("ws://127.0.0.1:8080");
rfc.onopen = function() {
log("Connection Opened.");
};
rfc.onclose = function() {
log("Connection Closed.");
};
function log(msg){
e = document.getElementById("chat_log");
e.innerHTML = e.innerHTML + "<li>" + msg + "</li>";
}
// Callable by the server
function from_others(agent, msg){
log(agent + ': "' + msg + '"');
}
rfc.client_function(from_others);
function joined_chat(agent){
log(agent + " joined the chat.");
}
rfc.client_function(joined_chat);
// Available on the server
function message(msg){}
message = rfc.server_function(message, null);
// events
function onsend(){
msg = document.getElementById("data").value;
document.getElementById("data").value = "";
message(msg);
log('You: "' + msg + '"');
}
</script>
</head>
<body>
<input type="text" id="data" onkeyup="if(event.keyCode==13){onsend();}" />
<button onclick='onsend()'>send</button>
<br/>
<ul id="chat_log">
</ul>
</body>
</html>