├── README.md
├── index.html
├── index.js
└── package.json
/README.md:
--------------------------------------------------------------------------------
1 | # android-socket.io-server-demo
2 |
3 | 1) install node
4 | 2) npm install from the root. This will install all the dependencies
5 | 3) node index.js - this will start the server
6 | 4) to change the port open index.js and change it in line number 29. Right now it is 3000
7 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Node Socket
6 |
7 |
10 |
11 |
12 | Hello Socket
13 |
14 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by sreejeshpillai on 09/05/15.
3 | */
4 | var app = require('express')();
5 | var http = require('http').Server(app);
6 | var io = require('socket.io')(http);
7 | app.get('/',function(req,res){
8 | res.sendFile(__dirname+'/index.html');
9 | })
10 | io.on('connection',function(socket){
11 | console.log('one user connected '+socket.id);
12 | socket.on('message',function(data){
13 | var sockets = io.sockets.sockets;
14 | /*sockets.forEach(function(sock){
15 | if(sock.id != socket.id)
16 | {
17 | sock.emit('message',data);
18 | }
19 | })*/
20 | socket.broadcast.emit('message', data);
21 | })
22 | socket.on('disconnect',function(){
23 | console.log('one user disconnected '+socket.id);
24 | })
25 | })
26 |
27 |
28 |
29 | http.listen(3000,function(){
30 | console.log('server listening on port 3000');
31 | })
32 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nodesockets",
3 | "version": "1.0.0",
4 | "description": "android socket application",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "make test"
8 | },
9 | "author": "sreejesh pillai",
10 | "license": "ISC",
11 | "dependencies": {
12 | "express": "^4.12.3",
13 | "nodemon": "^1.3.7",
14 | "socket.io": "^1.3.5"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------