25 |
} |
} |
26 |
|
|
27 |
socket.onmessage = function(msg){ |
socket.onmessage = function(msg){ |
28 |
append(msg); //Awesome! |
append(msg.data); //Awesome! |
29 |
} |
} |
30 |
|
|
31 |
socket.onclose = function(){ |
socket.onclose = function(){ |
42 |
|
|
43 |
socket.send(txt); |
socket.send(txt); |
44 |
|
|
45 |
|
$("#txt").val(""); |
46 |
|
|
47 |
} catch(exception) { |
} catch(exception) { |
48 |
append(exception); |
append(exception); |
49 |
} |
} |
50 |
}); |
}); |
51 |
|
|
52 |
|
$(document).keypress(function(e) { |
53 |
|
if(e.which == 13) { |
54 |
|
try { |
55 |
|
var txt = $("#txt").val(); |
56 |
|
append(txt); |
57 |
|
|
58 |
|
socket.send(txt); |
59 |
|
$("#txt").val(""); |
60 |
|
|
61 |
|
} catch(exception) { |
62 |
|
append(exception); |
63 |
|
} |
64 |
|
} |
65 |
|
}); |
66 |
|
|
67 |
}); |
}); |
68 |
|
|
69 |
|
|
70 |
</script> |
</script> |
71 |
|
|
72 |
</head> |
</head> |
74 |
|
|
75 |
<h2>Websocket test chat</h2> |
<h2>Websocket test chat</h2> |
76 |
|
|
77 |
<textarea rows="30" cols="160" id="log"></textarea> |
<textarea rows="30" cols="160" id="log" readonly></textarea> |
78 |
<br> |
<br> |
79 |
<input size=120 type="text" name="txt" id="txt"> |
<input size=120 type="text" name="txt" id="txt"> |
80 |
<button id="btn">Submit</button> |
<button id="btn">Submit</button> |