cant able to connect to flash in nodejs

I cant able to enter in onConnect function in nodeJS. All the thing is i am trying to connect to flash using nodejs as server.

my server.js is

 var net = require('net');

 var mySocket;

 var server = net.createServer(function(socket) {
   mySocket = socket;
   mySocket.on("connect", onConnect);
   mySocket.on("data", onData);
 });

 function onConnect()
 {
    console.log("Connected to Flash");
 }

 function onData(d)
 {
   if(d == "exit\0")
   {
      console.log("exit");
      mySocket.end();
      server.close();
    }
   else
   {
           console.log("From Flash = " + d);
            mySocket.write(d, 'utf8');
    }
 }

  server.listen(9001, "127.0.0.1");
  console.log("Connection Established");

could any one tell me where i went wrong?

Event connection is for class net.Server (the server) and connect is for class net.Socket (the client). When you create a server via net.createServer, the function you pass is automatically set as listener for connection event. From the API doc -

net.createServer([options], [connectionListener])

Creates a new TCP server. The connectionListener argument is automatically set as a listener for the 'connection' event.

The server has no connect event. To use connect create another create another client.js with following and execute it after running your server.js .

 var net = require('net');
 var port = 9001,
     host = '127.0.0.1';
 var socket = net.createConnection(port, host);
 console.log('Socket created.');
 socket.on('data', function (data) {
     console.log('RESPONSE: ' + data);
 }).on('connect', function () {
     socket.write("GET / HTTP/1.0\r\n\r\n");
 }).on('end', function () {
     console.log('DONE');
 });