var ws;
$().ready(function () {
$('#conn').click(function () {
//ws = new WebSocket('ws://' + window.location.hostname + ':' + window.location.port + '/Handler1.ashx?user=' + $("#user").val());
ws = new WebSocket('ws://192.168.85.128:8086/Handler1.ashx?user=' + $("#user").val());
//var host = 'ws://192.168.85.128:8085/api/WSChat?user='+$("#user").val();
//var host = "ws://192.168.85.128:8085/api/WSChat";
//webSocket = new WebSocket(host);
$('#msg').append('
正在连接
');ws.onopen = function () {
$('#msg').append('
已经连接
');}
ws.onmessage = function (evt) {
$('#msg').append('
' + evt.data + '
');}
ws.onerror = function (evt) {
$('#msg').append('
' + JSON.stringify(evt) + '
');}
ws.onclose = function () {
$('#msg').append('
已经关闭
');}
});
$('#close').click(function () {
ws.close();
});
$('#send').click(function () {
if (ws.readyState == WebSocket.OPEN) {
ws.send($("#to").val() + "|" + $('#content').val());
}
else {
$('#tips').text('连接已经关闭');
}
});
});
目的用户