Home > other >  Nodejs socket. IO connection issue
Nodejs socket. IO connection issue

Time:10-05


Client connection var socket=IO. Connect (& amp; amp; # 39; http://xxxx:9090& amp; # 39;) , the server receives the connection, but the client socket. The total connected to false what reason is this?

The code is as follows:

Server:

Var=HTTP server. CreateServer (function (the req, res) {
Res. WriteHead (200, {
'the content-type' : 'text/HTML. Charset=utf-8 '
});
//res. Write (" number: "+ numscount);
Res. The end ();
}), listen (19967, function () {
//the console log (' service opened 19967 ');

});

Var IO=socketio. Listen (server, {
PingTimeout: 60000,
PingInterval: 25000
});

IO. On (' connection ', function (socket) {
The console. The log (' connection is successful);
//numscount++; })

The client

The function myfun ()
{
Var socket=new IO. Connect (ws://115.29.7.107: "19967", {' reconnect ': false, "auto connect" : false, "connect timeout" : 100});

Socket. The connect ();

Socket. On (' connect ', function ()
{
The console. The log (' Client has connected to the server! ');
});

The console. The log (1);
The console. The log (socket);
The console. The log (2);
}

Window. The onl oad=myfun

  • Related