forked from MartinChavez/Node.js-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.html
More file actions
28 lines (24 loc) · 707 Bytes
/
socket.html
File metadata and controls
28 lines (24 loc) · 707 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Socket.io</title>
<!-- Include the socket.io library, Socket.IO servers automatically serve the client -->
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<script>
// Connect to the server
var socket = io.connect('http://localhost:8080');
<!-- Listens to the 'messages' event -->
socket.on('messages', function (data) {
console.log(data.socket);
});
socket.on('fromServer', function (data) {
console.log(data.fromServer);
});
<!-- Creates a new message and sends it to the server -->
socket.emit('fromClient', "fromClient");
</script>
</body>
</html>