Re: How to reuse a Soket and how it will work
by ikegami (Patriarch) on Feb 16, 2009 at 06:53 UTC
|
Yes, there's nothing stopping you from sending multiple requests over the same socket. The socket doesn't even know anything about requests and responses, just bytes. It all depends on the protocol used over the socket. For example, HTTP allows it, but only if Keep-Alive is requested and if the server supports it.
| [reply] |
|
|
Hi, thanks for the replay.... am working for IVR(Interactive voice Respone system) where in which i need to handle hundreds of calls in a second which will land into my server. Wen each call land in the server script is gonna execute which creates a socket. My script has a module which intern interact with one more server and will get a response through the socket created. This instance am explaining for a single call, but wen several call will land at a strech my script will execute that many times,that means script will create that many sockets for the comminication. Now my doubt is, instead of closing the socket each time after getting response how can I use the same socket for all the execute instances, if it is posiible please help me out in doing the same....
| [reply] |
|
|
What makes you optimize this part of the code(Socket creation), IMO creating socket for every IVR instance is a good idea and it won't affect the start of your application much.
if you want to make your script efficient/optimize there may be other areas in your script where you have to look in for optimization.
storing the socket handle, database handle etc; for later re-use is not needed in this case.
because if you take IVR other side caller is not going to be a machine; 99% of the times it would be human, to create and initialize a socket it won't take that much of time (it would happen in micro seconds or even less), the caller or you wouldn't even see a delay in execution speed of the script in this socket creation and initialization part.
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
| [reply] |
|
|
If I understood you correctly, you wanna reuse TCP connection established by one process in another process. That's possible if you establish connection in parent process and use it in child process. But you should maintain pool of connections in parent process in this case.
If your processes are not in a parent-child relationship, you can't share connections between them.
It would be very helpful if you demonstrate what you are trying to do with some code.
| [reply] |
Re: How to reuse a Soket and how it will work
by targetsmart (Curate) on Feb 16, 2009 at 09:32 UTC
|
But I want to know is there any way to use the same socket for more than one client
more than one client can connect to a server socket(IP and port).
are you restricting your client to bind to a specific port before connecting to server?, if you are doing so; what is the reason?.
if you aren't restricting your client to bind to a specific port, then don't worry; use IO::Socket::INET and connect to the server by specifying peeraddr and peerport. it will take care of local port binding. In this case you can run multiple instances of your client to send and receive data from server(provided your server must have configured to serve that many clients).
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
| [reply] |
|
|
Hi, Thanks for the response.
the server side the allocated port for communication is 3575.
So I have to interact wit that port only. As the script that contain the module for the creation of thr socket will execute
several time that many sockets are gonnaa create. So my doubt is that can I use the socket that i created in one execution instance to communicate for the other execution instances.
Hope its clear...Please help me out...
| [reply] |
|
|
Can I use the socket that i created in one execution instance to communicate for the other execution instances
IMO it is not possible/not recommended for processes to share same socket handle(single IP and PORT)
Even though you try that, all instances writing to the same socket will be a mess; unless every request/response has a identification mechanism of itself(like sequence number).
but your problem can be solved using other ways.
if you really want to use only one socket, have one dedicated program for socket connection in the client side(which would always be running) which sends and receives data from server, all other your IVR instances can use a Message queue or a shared memory mechanism to connect with this dedicated socket program to send/receive data.
The above idea brings more complexity to your code, you have to craft it properly. But one common solution is, let all the instances create its own socket, the memory that is going to be used for socket creation is very minimum, the number of socket connections per system also can be tuned(increased/decreased).
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
| [reply] |
|
|
|
|
It is better you can call the function for creating a socket at once in the initial part. After that you can send and receive a message using that socket descriptor. If you want more please put your code.
| [reply] |