<!DOCTYPE html>
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
|
<title></title>
|
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.11.3.min.js"></script>
|
<script>
|
var ws;
|
$().ready(function () {
|
$('#conn').click(function () {
|
ws = new WebSocket('wss://121.196.36.24:8001' + '/api/Send?clientName=' + '456');
|
$('#msg').append('<p>正在连接</p>');
|
|
ws.onopen = function () {
|
$('#msg').append('<p>已经连接</p>');
|
}
|
ws.onmessage = function (evt) {
|
$('#msg').append('<p>' + evt.data + '</p>');
|
}
|
ws.onerror = function (evt) {
|
$('#msg').append('<p>' + JSON.stringify(evt) + '</p>');
|
}
|
ws.onclose = function () {
|
$('#msg').append('<p>已经关闭</p>');
|
}
|
});
|
|
$('#close').click(function () {
|
ws.close();
|
});
|
|
$('#send').click(function () {
|
if (ws.readyState == WebSocket.OPEN) {
|
ws.send($("#to").val() + "|" + $('#content').val());
|
}
|
else {
|
$('#tips').text('连接已经关闭');
|
}
|
});
|
|
});
|
</script>
|
</head>
|
<body>
|
<div>
|
<input id="user" type="text" />
|
<input id="conn" type="button" value="连接" />
|
<input id="close" type="button" value="关闭" /><br />
|
<span id="tips"></span>
|
<input id="content" type="text" />
|
<input id="send" type="button" value="发送" /><br />
|
<input id="to" type="text" />目的用户
|
<div id="msg">
|
</div>
|
</div>
|
</body>
|
</html>
|