# websocket sample ``` // ブラウザで実行する JavaScript var ws = new WebSocket("ws://172.27.2.245:8080"); ws.addEventListener("open", function(event) { console.log("WebSocket 接続完了"); // サーバからメッセージを受け取ったときの処理 //ws.addEventListener("message", function(e) { // console.log("Message Recieved: " + e.data); //}); // サーバにデータを送信するときの処理 // msgJson = { type: "interphone", interphone: M, reception: N } // M: interphone 押した回数、N: ドア開いた回数 // ws.send(JSON.stringify( { type: "interphone", interphone: 10, reception: 5 } )); // msgJson = { type: "human", time: xxxx } // time (ms) // ws.send(JSON.stringify( { type: "human", time: 1000 } )); // msgJson = { type: "fukai", flag: x } // flag: 0|1|2 ws.send(JSON.stringify( { type: "fukai", flag: 0 } )); }); ```