-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsocket.html
More file actions
71 lines (57 loc) · 2.21 KB
/
Copy pathwebsocket.html
File metadata and controls
71 lines (57 loc) · 2.21 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="./socket.io.js"></script>
<script type="text/javascript">
;var WSS = function () {
var debug = 1;
window.WebSocket = window.WebSocket || window.MozWebSocket;
var websocket;
init_socket = function(){
websocket = new WebSocket('ws://10.80.71.208:1337');
websocket.onopen = function () {
$(".status").html("Conectado.").css('color', 'green');
};
websocket.onerror = function () {
$(".status").html("Desconectado.").css('color', 'red');
setTimeout("init_socket()",5000); // Cada 5 segundos verifica si el socket esta online.
};
websocket.onmessage = function (message) {
var obj = JSON.parse(message.data);
$('#last-update').append('<p>Recived: '+obj.text+'</p>');
};
};
return {
init: function () {
init_socket();
},
send: function(texto){ websocket.send(texto); }
};
}();
$(document).ready(function(){
// Metodo con modulo WebSockets
// WSS.init();
//----------------------------------------------------------------------------------------------------------
// Metodo con modulo Socket.IO
//----------------------------------------------------------------------------------------------------------
$('button').click(function(e) {
e.preventDefault();
WSS.send($('input').val());
$('input').val('');
});
//$.get( '/searching',parameters, function(data) { $('#results').html(data); } );
});
</script>
</head>
<body>
<h1>WebSocket: <span class="status">-</span></h1>
<hr>
<!-- form>
<input type="text" />
<button>Send</button>
</form -->
<div id='last-update'></div>
</body>
</html>