0

hi friends i have one question about chat application with node js and socket io

i have one website and its application in application user send message to web and web will answered that user so how can i create this type of application

my idea is like in web web user send message to client no 10 to node server and node server will send only that user which client no is 10

this is my node js and socket io code for basic chat

var port = "3000"
var express = require('express');  
var app = express();  
var server = require('http').createServer(app);  
var io = require('socket.io')(server);
var ioClientList = [];
app.use(express.static(__dirname + '/bower_components'));  
app.get('/', function(req, res,next) {  
    // res.sendFile(__dirname + '/index.html');
    res.send('<h1>Hello world</h1>');
  });

server.listen(port, function(){
 console.log('listen on port'+ port);
}); 

io.sockets.on('connection', function(socket) {
    console.log('dddd');

    socket.on('message', function(message) {
        socket.broadcast.emit('message', message);
    });

   socket.on('chat', function(message) {
        socket.broadcast.emit('chat', message);
    });

  

});

so how can i store connected client with send its ID and send message using that ID

please help me for this question

Trushar Narodia
  • 366
  • 4
  • 19

0 Answers0