forked from YeeYoungHan/cpphttpstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSocketEchoClient.html
More file actions
52 lines (42 loc) · 1.1 KB
/
WebSocketEchoClient.html
File metadata and controls
52 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
var ws;
$( document ).ready( function()
{
var txtRecv = $('#Recv');
ws = new WebSocket("ws://localhost:8080");
// websocket 서버에 연결되면 연결 메시지를 화면에 출력한다.
ws.onopen = function(e){
txtRecv.append( "connected<br>" );
};
// websocket 에서 수신한 메시지를 화면에 출력한다.
ws.onmessage = function(e){
txtRecv.append( e.data + "<br>" );
};
// websocket 세션이 종료되면 화면에 출력한다.
ws.onclose = function(e){
txtRecv.append( "closed<br>" );
}
} );
// 사용자가 입력한 메시지를 서버로 전송한다.
function sendMessage()
{
var txtSend = $('#Send');
ws.send( txtSend.val() );
txtSend.val( "" );
}
</script>
</head>
<body>
<form>
<input id="Send" type="text">
<button type="button" onclick="sendMessage();">Send</button>
</form>
<div id="Recv">
</div>
</body>
</html>