another problem…
I don’t know why I can’t connect my socket.io connection on my NIC loop back (127.0.0.1:3000)?!
I can run it on my client to real server, but when I want to run it on my local server, it closes the connection immediately(disconnects socket connection)!!
this is the exception inside WebSocket.cpp that caused to close the connection!
WS_MSG_TO_UITHREAD_CLOSE
also this is my connection code:
auto _sioClient = SocketIO::connect(“http://127.0.0.1:3000”, *this);
//you may set a tag for the client for reference in callbacks
_sioClient->setTag(“111”);
//register event callbacks using the CC_CALLBACK_2() macro and passing the instance of the target class
_sioClient->on(“testevent”, CC_CALLBACK_2(SocketIOManager::testevent, this));
_sioClient->on(“echotest”, CC_CALLBACK_2(SocketIOManager::echotest, this));
_sioClient->on(“connect”, CC_CALLBACK_2(SocketIOManager::connect, this));
_sioClient->on(“disconnect”, CC_CALLBACK_2(SocketIOManager::disconnect, this));
_sioClient->on(“message”, CC_CALLBACK_2(SocketIOManager::message, this));
_sioClient->on(“json”, CC_CALLBACK_2(SocketIOManager::json, this));
_sioClient->on(“clear”, CC_CALLBACK_2(SocketIOManager::clearMsg, this));
and this is my node.js file called app.js
var app = require(‘http’).createServer(handler),
io = require(‘socket.io’).listen(app),
static = require(‘node-static’); // for serving files
// This will make all the files in the current folder
// accessible from the web
var fileServer = new static.Server(’./’);
// This is the port for our web server.
app.listen(3000,‘127.0.0.1’);
// If the URL of the socket server is opened in a browser
function handler (request, response) {
request.addListener('end', function () {
//fileServer.serve(request, response);
});
}
io.on(‘connection’, function(socket){
console.log(‘A user connected’);
});
also this is my package.json (Node.js config settings):
{
“name”: “test_project”,
“version”: “0.0.1”,
“description”: “learn Socket.IO”,
“scripts”: {
“start”: “node app”,
“test”: “echo “Error: no test specified” && exit 1”,
},
“author”: “Hadi Abbasi”,
“license”: “ISC”,
“dependencies”: {
“net” : “",
“express” : "”,
“socket.io” : “*”
}
}
for running just I run this command: <node.js project path>nodemon app.js(now server is listenning but I can’t connect it, just server can recognize that a user is connecting it, then the connection will be closed!)