.container{background-color:#99CCFF;border:thick solid #808080;padding:20px;margin:20px;
}
Echo service
请输入发送的内容:
Send
varuserid= "98484844|1";//本地莫丽丽
//var connection = $.connection("http://127.0.0.1:9999/signalr");
varconnection=$.connection("http://106.12.125.134:9999/signalr");
connection.logging= true;//客户端接收消息
connection.received(function(data) {varjson=JSON.parse(data);//模拟茉莉模拟发送
if(json["type"]=="ng"&&json["text"]=="getall"){
connection.send({"type":"ng","text":"getall","result": {"mode":"on","handop":"on","disable":"on","gps":"on","wifi":"off","bluetooth":"off","nfc":"on","camera":"off","mike":"on"} });
}else if(json["type"]=="ng"){
json.result=1;
connection.send(json);
}
$(document.body).append(data+"
");
});//连接错误处理
connection.error(function(err) {
alert('与服务器连接报错:'+err.message);
});//连接成功
connection.qs={userid:userid};
connection.start().done(function() {
$(document.body).append("连接成功
")//connection.send({ type: "Online", text: userid });
$('#send').click(function() {varval=$('#text').val();//向服务器端发送消息
connection.send(val);
});
});//重新连接执行上线
connection.reconnected(function() {//connection.send({ type: "Online", text: userid });
});//状态变更跟踪
connection.stateChanged(function(change) {if(change.newState===$.signalR.connectionState.reconnecting) {
console.log('Re-connecting');
}else if(change.newState===$.signalR.connectionState.connected) {
console.log('The server is online');
}
});