Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
home
/
nongapp.eemo.co.kr
/
public_html
/
www
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//home/nongapp.eemo.co.kr/public_html/www/test_chat.php
<!DOCTYPE html> <title>WebSocket Test Page</title> <script> document.onreadystatechange = function () { if (document.readyState === "complete") { setTimeout(function(){ var is_sock_conn=false; var log = function(s) { console.log(s); if (document.readyState !== "complete") { log.buffer.push(s); } else { document.getElementById("output").innerHTML += (s + "\n") } } log.buffer = []; url = "wss://nongapp.eemo.co.kr/myws"; w = new WebSocket(url); w.onopen = function() { is_sock_conn=true; log("open"); //w.send("thank you for accepting this Web Socket request"); } w.onmessage = function(e) { console.log(e.data); log(e.data); var obj = JSON.parse(e.data); if(obj.tot != null) { $('#sp_chat_conn').html(obj.tot); } } w.onclose = function(e) { log("closed"); is_sock_conn=false; setTimeout(function(){ w = new WebSocket(url); }, 1000); } log(log.buffer.join("\n")); document.getElementById("sendButton").onclick = function() { console.log(document.getElementById("inputMessage").value); // 객체 생성 var obj = new Object() ; obj.id = "홍익농장" ; obj.data= document.getElementById("inputMessage").value ; w.send(JSON.stringify(obj)); } // 간지나게 엔터키 누르면 메시지 날림 document.getElementById("inputMessage").onkeypress = function() { if (event.keyCode == '13') { // 객체 생성 var obj = new Object() ; obj.id = "홍익농장" ; obj.data= document.getElementById("inputMessage").value ; w.send(JSON.stringify(obj)); document.getElementById("inputMessage").value = ""; } } setInterval(function(){ if(is_sock_conn==true) { var obj = new Object() ; obj.id = "홍익농장" ; obj.data=""; w.send(JSON.stringify(obj)); } else { //w = new WebSocket(url); } }, 1000); }, 100); } } </script> <input type="text" id="inputMessage"> <button id="sendButton">Send</button> <pre id="output"></pre>