Socket.Io+HttpWebRequest 请求Api
Socket 接收代码
1 <html> 2 <head> 3 <title>Socket Client Demo</title> 4 <script src="./socket.io.js"></script> 5 <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> 6 </head> 7 <body> 8 <div> 9 连接状态:<input id="status" name="status"/> 10 </div> 11 <div id="message"></div> 12 <div> 13 <button onclick="javascript: socket.connect()">连接</button> 14 <button onclick="javascript: socket.disconnect()">断开连接</button> 15 </div> 16 17 <script> 18 var socket = io.connect('http://10.10.112.58:3002?employee_code=code1'); 19 $("#status").val("已经连接"); 20 socket.on('ping_custom', function( data ) { 21 console.log(data); 22 }); 23 24 socket.on("receiver_message", function(data){ 25 26 $("#message").append('<div>' + data["title"] + '</div>'); 27 28 socket.emit("receiver_message_callback",{ 29 message_receiver_id: data["message_receiver_id"] 30 }); 31 }); 32 33 socket.on('disconnect', function() { 34 console.log("与服务其断开"); 35 $("#status").val("断开连接"); 36 }); 37 socket.on("connect", function(){ 38 console.log("连接到服务器"); 39 $("#status").val("已经连接"); 40 }) 41 </script> 42 43 </body> 44 45 </html>
WebApi请求代码