in reply to How to reuse a Soket and how it will work

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.
  • Comment on Re: How to reuse a Soket and how it will work

Replies are listed 'Best First'.
Re^2: How to reuse a Soket and how it will work
by madhu.hanigadde (Novice) on Feb 16, 2009 at 09:43 UTC
    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...
      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.
        Yep I understood thanks a lot...
      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.