客户端: <!DOCTYPE html> <html> <head> <title></title> <style> #win{ border:1px solid #ccc; padding:20px ; color:#333; line-height:2em; } .input{ padding:10px 0px; text-align:left;} .input input{ width:200px;} </style> </head> <body> <div id=”win”></div> <div><input id=”text”><button id=”send”>发送</button><button id=”disconnect”>断开连接</button></div> <script> function log(d){ var logDiv=document.createElement(“div”); logDiv.innerHTML=d; document.getElementById(“win”).appendChild(logDiv); } //创建websocket连接 var socket=new WebSocket(“ws://localhost:12345/websocket/server.php”); //绑定连接成功事件 socket.onopen=function(){ log(“Socket ReadyState:”+socket.readyState); //socket.send(“hi”); }; //绑定接收到信息事件 socket.onmessage=function(e){ log(e.data); } //绑定关闭连接事件 ...Read More
檬檬前端行
路漫漫其修远兮
近期评论