61 Star 147 Fork 64

xioxin / WebSocket.class.php

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.html 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
xioxin 提交于 2013-06-18 15:42 . 添加例程
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>websocket_TEST</title>
</head>
<body>
<textarea class="log" style="width: 100%; height: 500px;">
=======websocket======
</textarea>
<input type="button" value="连接" onClick="link()">
<input type="button" value="断开" onClick="dis()">
<input type="text" id="text">
<input type="button" value="发送" onClick="send()">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
function link(){
var url='ws://192.168.0.200:8000';
socket=new WebSocket(url);
socket.onopen=function(){log('连接成功')}
socket.onmessage=function(msg){log('获得消息:'+msg.data);console.log(msg);}
socket.onclose=function(){log('断开连接')}
}
function dis(){
socket.close();
socket=null;
}
function log(var1){
$('.log').append(var1+"\r\n");
}
function send(){
socket.send($('#text').attr('value'));
}
function send2(){
var json = JSON.stringify({'type':'php','msg':$('#text2').attr('value')})
socket.send(json);
}
</script>
</body>
</html>
PHP
1
https://gitee.com/xioxin/websocket-class-php.git
git@gitee.com:xioxin/websocket-class-php.git
xioxin
websocket-class-php
WebSocket.class.php
master

搜索帮助