{"id":258,"title":"html5 web socket\u5b9e\u4f8b","good":0,"bad":0,"hit":1794,"created_at":"2017-02-22 17:05:47","content":"

<!DOCTYPE html><\/p>

<html><\/p>

<head><\/p>

<meta charset="utf-8"><\/p>

<title>Testing websockets<\/title><\/p>

<\/head><\/p>

<body><\/p>

<div><\/p>

  <input type="submit" value="Start" onclick="start()" \/><\/p>

<\/div><\/p>

<div id="messages"><\/div><\/p>

<script type="text\/javascript">  <\/p>

var webSocket = new WebSocket('ws:\/\/192.168.3.10:6898');<\/p>

function start() {<\/p>

\tvar send={"cmd":"web.send_msg_to_kh","req_id":4,"params":{"from_sid":"sid_kf_31237","to_sid":"sid_kh_14168","msg":"ismd_msg:\/\/hurong"}};<\/p>

\tvar str=JSON.stringify(send);\/\/\u7279\u522b\u6ce8\u610f\uff0c\u8fd9\u91cc\u4f20\u7684\u8981\u8f6c\u6210\u5b57\u7b26\u4e32<\/p>

\twebSocket.send(str);<\/p>

\twebSocket.close();<\/p>

\treturn false;<\/p>

}<\/p>

<\/script><\/p>

<\/body><\/p>

<\/html><\/p>

<\/p>

\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cws.send();\u8981\u5728ws.onopen\u4e4b\u540e\uff0c\u5426\u5219\u4f1a\u62a5\u9519<\/p>

<html><\/p>

<head><\/p>

<meta charset="utf-8"><\/p>

<title>\u8fd9\u662f\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b<\/title><\/p>

<\/head><\/p>

<body><\/p>

<p id="info"><\/p><\/p>

<script type="text\/javascript"><\/p>

\tvar ws = new WebSocket('ws:\/\/192.168.3.10:6898');<\/p>

\tws.onopen = function(){<\/p>

\t\tinfo.innerHTML = '\u8fde\u63a5\u6210\u529f\u5efa\u7acb<br\/>';<\/p>

\t\tvar str='{"cmd":"web.send_msg_to_kh","req_id":4,"params":{"from_sid":"sid_kf_31237777","to_sid":"sid_kh_14168","msg":"ismd_msg:\/\/hur"}}';<\/p>

\t\tws.send(str);<\/p>

\t\tws.close();<\/p>

\t}<\/p>

<\/script><\/p>

<\/body><\/p>

<\/html><\/p>

<\/p>"}