Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
117 lines (112 loc) · 3.76 KB
/
Copy pathindex.html
File metadata and controls
117 lines (112 loc) · 3.76 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<title>IO socket Test - Scott Kellie</title>
<meta charset = "UTF-8" />
<style type = "text/css">
h1 {
text-align: center;
}
.error {
color: red;
}
.response {
color: blue;
}
fieldset {
width: 80%;
margin: auto;
text-align: center;
-moz-box-shadow: 10px 10px 10px #000000;
-webkit-box-shadow: 10px 10px 10px #000000;
}
#output {
font-family: monospace;
width: 80%;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
background-color: #eeeeee;
padding: 1em;
border: 5px groove #cccccc;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
-moz-box-shadow: 20px 20px 20px #000000;
-webkit-box-shadow: 20px 20px 20px #000000;
}
</style>
<script>src="/socket.io/socket.io.js"></script>
<script language="javascript" type="text/javascript">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
$(function(){
var iosocket = io.connect();
iosocket.on('connect', function () {
$('#incomingChatMessages').append($('<li>Connected</li>'));
iosocket.on('message', function(message) {
$('#incomingChatMessages').append($('<li></li>').text(message));
});
iosocket.on('disconnect', function() {
$('#incomingChatMessages').append('<li>Disconnected</li>');
});
});
$('#outgoingChatMessage').keypress(function(event) {
if(event.which == 13) {
event.preventDefault();
iosocket.send($('#outgoingChatMessage').val());
$('#incomingChatMessages').append($('<li></li>').text($('#outgoingChatMessage').val()));
$('#outgoingChatMessage').val('');
}
});
});
function connect(){
//open socket
iosocket = io.connect();
iosocket.send('ConnectionButtonClicked');
alert('IOSOCKET CONNECTED');
output.innerHTML = "connecting..." ;
} // end connect
function sendMessage(){
//get message from text box
txtMessage = document.getElementById("txtMessage");
//make variable of message
message = txtMessage.value;
//pass message to server
iosocket.send(message);
alert("<p>MESSAGE SENT: " + message + "</p>");
}
function disconnect(){
iosocket.close();
alert('disconnected');
}
</script>
</head>
<body>
<form action = "">
<fieldset>
<button type = "button"
onclick = "connect()">
connect to server
</button>
<label for = "txtMessage">
<input type = "text"
id = "txtMessage"
value = "HTML5" />
</label>
<button type = "button"
onclick = "sendMessage()">
send message
</button>
<button type = "button"
onclick = "disconnect()">
disconnect
</button>
<ul>Incoming Chat: <ul id="incomingChatMessages"></ul>
<input type="text" id="outgoingChatMessage">
</fieldset>
</form>
</body>
</html>