How to trigger messages using socket.io?

How is it possible to send a message using a button in html5?

here is my code:

server:

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


io.on('connection', function(client){
    client.send('{"success": 1}');
    client.on('message', function(data) {
        console.log('Client:', data); 
    }); 
    client.on('disconnect', function() {
        console.log('Goodbye');
    }); 
});

client:

<!DOCTYPE html>
<html>

<head>
<script src="http://192.168.0.102:72/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://192.168.0.102:72');
function doit(){
  socket.on('message', function(data) {
    socket.send("hi there");
   });
}
</script>

</head>

<body>
    <button name="Klickme" type="button" onclick="doit();">On!</button>
    <button id="off" type="button" onclick="close();">Off!</button>
</body>

</html>

I get no error on my client/server, but I don´t get the message either. Can Somebody give me a hint? thanks!!!

on is used when you want to listen to an event that is sent from the server, if you want to send a message you should use emit instead:

socket.emit('message', { my: 'data' });

Your client waits for message from server when you click the button (before it sends hi there). But the server sends the message as soon as the page is loaded and client connects to server. That is the only message server sends. So client keeps waiting for message from server. Change doit() to this

function doit(){
    socket.send("hi there");
}