※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※サーバースクリプト(char_wsh.py)
from mod_pywebsocket import msgutil
arr = []
def web_socket_do_extra_handshake(request):
    arr.append(request)
    pass
def web_socket_transfer_data(request):
    while True:
        s = msgutil.receive_message(request)
        for connect in arr:
            try:
                msgutil.send_message(connect, s)
            except:
                arr.remove(connect)
※HTMLファイル
<!DOCTYPE html>
	<head>
		<meta charset="utf-8" />
		<title>Sample Page</title>
		<script type="text/javascript">
		<!--
		var socket;
		
		function init(){
			socket = new WebSocket("ws://localhost:8800/chat");
			socket.onmessage = function(e){
				var p = document.getElementById("msg");
				var s = p.innerHTML
				p.innerHTML = e.data + "<br>" + s;
			}
		}
		
		function action(){
			var str = document.getElementById("text1").value;
			socket.send(str);
		}
		
		init();
		//-->
		</script>
	</head>
	<body>
		<h1>サンプル</h1>
		<input type="text" id="text1">
		<input type="button" onclick="action();" value="send">
		<hr>
		<p id="msg">message...</p>
	</body>
</html>
| << 前へ |