socket.io-clusterhub icon indicating copy to clipboard operation
socket.io-clusterhub copied to clipboard

It is not working with multi namespace

Open nguyenvansuai opened this issue 11 years ago • 18 comments

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

nguyenvansuai avatar Feb 13 '15 07:02 nguyenvansuai

I don't understand what the expected result is, and what you are getting. Can you elaborate?

fent avatar Feb 13 '15 12:02 fent

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

nguyenvansuai avatar Feb 13 '15 13:02 nguyenvansuai

Yeah some sample code would help me understand the issue more.

fent avatar Feb 13 '15 17:02 fent

update?

fent avatar Feb 23 '15 12:02 fent

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

nguyenvansuai avatar Feb 24 '15 13:02 nguyenvansuai

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.

fent avatar Feb 24 '15 15:02 fent

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

nguyenvansuai avatar Feb 25 '15 00:02 nguyenvansuai

Have you got the code?

nguyenvansuai avatar Feb 26 '15 06:02 nguyenvansuai

I'm assuming you're using socket.io version <= 0.9.0?

fent avatar Mar 03 '15 06:03 fent

yes, Iam using version <= 0.9.0

nguyenvansuai avatar Mar 03 '15 06:03 nguyenvansuai

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.

fent avatar Mar 03 '15 07:03 fent

You can follow steps:

  1. run example.js in using_socket.io-clusterhub folder
  2. open client.html using browser, you will get alert "connected"
  3. once reconnect, it still working.( you can test by the way stop server and start again)
  4. click on "Make new service" on browser, server will make a new service for name space "test"
  5. 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

nguyenvansuai avatar Mar 03 '15 07:03 nguyenvansuai

add more explain, If you use root_version, everything work properly if you use cluster_without_socket.io-clusterhub. step 3 is not working

nguyenvansuai avatar Mar 03 '15 07:03 nguyenvansuai

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.

fent avatar Mar 03 '15 07:03 fent

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

nguyenvansuai avatar Mar 03 '15 07:03 nguyenvansuai

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.

fent avatar Mar 03 '15 07:03 fent

Can you give me snippet code for this. THanks for advance

nguyenvansuai avatar Mar 03 '15 07:03 nguyenvansuai

Dear, I found down the solution, thanks

nguyenvansuai avatar Mar 03 '15 08:03 nguyenvansuai