It is not working with multi namespace
Dear, I recognize that in my situation, it is not working properly but it's too hard to describe or name this is my code
var app = require('socket.io');
var store = new (require('socket.io-clusterhub'));
var server;
server = app.listen(1234);
server.configure(function () {
server.set('store', store);
});
function makeService (namespace, io) {
io.on('make_new_service ',function (socket) {
var new_io = server.of('/test');
makeService('test',new_io);
})
// do something here
}
for(namespace=1;i<10;i++){ var io = server.of('/'+namespace); makeService(i,io ); } /////////////// 10 service is make by "for" statement, they work like a charm ( same as using only one process) But if make_new_service event is call, it make new service. and this service is not working properly ( same as never using socket.io-clusterhub)
Can you consider this issue.
THank you
I don't understand what the expected result is, and what you are getting. Can you elaborate?
Hi, Fent I am going to build application using socket. everything is working well. so now i try to using cluster and i am facing problem:
- socket clients can not communicate together if them connect to different process id
- socket client cannot reconnect: (the error: client not handshaken client should reconnect)
I tried to search for the solution a long time, finally I find out, that is you module "socket.io-clusterhub". When I using your module, both of above issues is solved. According to my above code. all of client that connect to 10 io make by "for" statement CAN communicate ( emit, on,....). But if make_new_service event is call, it make new service and clients connected to this io can not communicate and reconnect. the issue is same as before using "socket.io-clusterhub". DO you understand i mean? if not, I will try create sample code, and sent to you. Thank you so much for reading
Yeah some sample code would help me understand the issue more.
update?
hi, you can get my example code at http://31.220.48.113:23245/example.zip for more explain, you can read at read more file and above comment. This example only reappears issue "cannot reconnect", for another issue ( "socket clients can not communicate together" ) I think that it's same thing. Thank you verry much
can you put this up on github, like on a gist? I'd rather not download a zip from a site I don't know.
Dear, I sure that it is safe. you just click on the link to download it. because I am not familiar with github so it too hard for me to upload on github. Or you can get it from google drive https://drive.google.com/file/d/0B3ib74hGOYmGN1NGTVhHTUJqTkk/view?usp=sharing
Have you got the code?
I'm assuming you're using socket.io version <= 0.9.0?
yes, Iam using version <= 0.9.0
I just tried the example with clusterhub. I can connect and get a response, and when the new service is created, I can connect to that namespace too, and communicate.
You can follow steps:
- run example.js in using_socket.io-clusterhub folder
- open client.html using browser, you will get alert "connected"
- once reconnect, it still working.( you can test by the way stop server and start again)
- click on "Make new service" on browser, server will make a new service for name space "test"
- open client_new_service.html, sometime it's woking ( it mean you get alert "client conneted to ID PID ") or not working ( it's mean no alert). if it's woking, you open taskmanager ( in windows) find processID = PID and force stop it, you can see that client.html will alert to connect new PID, but client_new_service.html will not.
Thanks
add more explain, If you use root_version, everything work properly if you use cluster_without_socket.io-clusterhub. step 3 is not working
That's because the test namespace is only created when the client emits the make_service event, not when the server starts, or when the client connects.
If a child process goes down, it won't recreate that namespace because doing so is not part of it starting.
OMG, I am really stupid, that is reason, thanks you very much, this is my issue. So do you know how to make_service run for all of child process.
Thank you
Look in the socket.io docs to see how to set/get state in storage so that child processs can get state from the master. But if the master dies, your state will die with it if it's kept in memory.
Can you give me snippet code for this. THanks for advance
Dear, I found down the solution, thanks