2 Lincense: Public Domain
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <title>Sample of web_socket.js</title>
9 <!-- Include these three JS files: -->
10 <script type="text/javascript" src="swfobject.js"></script>
11 <script type="text/javascript" src="web_socket.js"></script>
13 <script type="text/javascript">
15 // Set URL of your WebSocketMain.swf here:
16 WEB_SOCKET_SWF_LOCATION = "WebSocketMain.swf";
17 // Set this to dump debug message from Flash to console.log:
18 WEB_SOCKET_DEBUG = true;
20 // Everything below is the same as using standard WebSocket.
26 // Connect to Web Socket.
27 // Change host/port here to your own Web Socket server.
28 ws = new WebSocket("ws://localhost:10081/");
30 // Set event handlers.
31 ws.onopen = function() {
34 ws.onmessage = function(e) {
35 // e.data contains received string.
36 output("onmessage: " + e.data);
38 ws.onclose = function() {
41 ws.onerror = function() {
48 var input = document.getElementById("input");
49 // You can send message to the Web Socket using ws.send.
51 output("send: " + input.value);
56 function onCloseClick() {
60 function output(str) {
61 var log = document.getElementById("log");
62 var escaped = str.replace(/&/, "&").replace(/</, "<").
63 replace(/>/, ">").replace(/"/, """); // "
64 log.innerHTML = escaped + "<br>" + log.innerHTML;
68 </head><body onload="init();">
69 <form onsubmit="onSubmit(); return false;">
70 <input type="text" id="input">
71 <input type="submit" value="Send">
72 <button onclick="onCloseClick(); return false;">close</button>