Skip to content

Commit 1a2634a

Browse files
author
MartinChavez
committed
Format document
1 parent 9b02fd8 commit 1a2634a

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

13 - Socket.io.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/* Web Sockets */
22
/*
3-
- Web sockets allow the creation of connections between clients and server.
4-
- On these connections data can flow (back adn forward) in real time
5-
*/
3+
- Web sockets allow the creation of connections between clients and server.
4+
- On these connections, data can flow (back and forward) in real time
5+
*/
66

77
/* Socket.io */
88
/*
9-
- Great tool for real-time applications
10-
- Provides fall-backs in case the client doesn't support web sockets
9+
- Great tool for real-time applications
10+
- Provides fallbacks in case the client doesn't support web sockets
1111
12-
Install by running:
13-
npm install --save socket.io
14-
*/
12+
Install by running:
13+
npm install --save socket.io
14+
*/
1515
var express = require('express');
1616
var app = express();
1717
// Create an http server and dispatch the requests to express
@@ -20,34 +20,34 @@ var server = require('http').createServer(app);
2020
var io = require('socket.io')(server);
2121

2222
// Listen for connection events (on socket.io) and define the callback function
23-
io.on('connection', function(client){
23+
io.on('connection', function (client) {
2424
console.log('Client connected...');
2525
// Emits the 'messages' event on the clients and sends the object {socket:io}
26-
client.emit('messages', {socket:'i.o'})
26+
client.emit('messages', {socket: 'i.o'})
2727

28-
client.on('fromClient', function(data){
28+
client.on('fromClient', function (data) {
2929
console.log(data);
3030
// Use broadcast to send a message to all the clients that are connected
31-
client.broadcast.emit("fromServer", {fromServer:'fromServer'});
31+
client.broadcast.emit("fromServer", {fromServer: 'fromServer'});
3232
});
3333

3434
})
3535

36-
app.get('/', function(req,res){
36+
app.get('/', function (req, res) {
3737
res.sendFile(__dirname + '/socket.html');
3838
});
3939

4040
server.listen(8080);
4141

4242
/*
43-
Run the following cmd to start node and create the scoket.io server:
44-
node '.\13 - Socket.io.js'
43+
Run the following cmd to start node and create the scoket.io server:
44+
node '13 - Socket.io.js'
4545
46-
- See socket.html for client-side code
46+
- See socket.html for client-side code
4747
48-
On your browser: localhost:8080
48+
On your browser: localhost:8080
4949
50-
Expected response:
50+
Expected response:
5151
- console.log with "i.o", numbers should be printed
5252
- On node, the numbers should keep counting up
5353
*/

0 commit comments

Comments
 (0)