Skip to content
Advertisement

how to my receiver is typing a message and show on my browser

i want to check the user is typing a message and want to display it in my chat box, i know setting database flag and checking it by timeinterval function, but i think it should be slow method, is there any way to check it? by the users’s machine ip/id .

Advertisement

Answer

I have found that using sockets is the only good solution for achieving that. https://wisembly.github.io/elephant.io/ .

PHP server side:

use ElephantIOClient as Elephant;

$elephant = new Elephant('http://localhost:8000', 'socket.io', 1, false, true, true);

$elephant->init();
$elephant->send(
    ElephantIOClient::TYPE_EVENT,
    null,
    null,
    json_encode(array('name' => 'foo', 'args' => 'bar'))
);
$elephant->close();

echo 'tryin to send `bar` to the event `foo`';

Socket.io server side:

var io = require('socket.io').listen(8000);

io.sockets.on('connection', function (socket) {
  console.log('user connected!');

   socket.on('foo', function (data) {
     console.log('here we are in action event and data is: ' + data);
   });
});
                    
                
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement