Can I use Singleton structure for sockets connection to my node server ? I want to use only one socket to transfer all required data from client(website) to server(node server). Is it possible? If possible then how ?
Asked
Active
Viewed 896 times
2
-
You can use a Singleton structure to store any kind of data you want. You can certainly put a socket in it if you want. Since the singleton requires a variable to put it in, you could also just store the socket in that variable and not use anything more complicated than that. Beyond that, I can't really tell what else your question is asking. – jfriend00 Apr 15 '15 at 06:49
-
@jfriend00 i want to transfer required data from different pages (website) to node server through single socket because i have large number of users issue on my current structure (multiple sockets) is http://stackoverflow.com/questions/29536649/node-server-crashes-after-few-hours/ – Irtiza shahid Apr 15 '15 at 07:24
-
How it is possible that one socket can transfer all data from different page ? how it is possible ? – Irtiza shahid Apr 15 '15 at 07:26
-
1You can't do that. Each separate page has an entirely new and separate Javascript context. You can't open a socket in one page and then, after that page has closed, use that socket in another page. Instead, you would have to create a new socket for the 2nd page. If you are running into a limit for the number of sockets in node.js, that limit can be increased. – jfriend00 Apr 15 '15 at 07:28
-
1If you just want to transfer data from a web page to your server, then you should just use an ajax call. Those are short duration so you are less likely to run out of sockets on the node.js server. – jfriend00 Apr 15 '15 at 07:31