2 Replies Latest reply: Apr 1, 2007 6:16 PM by 807606 RSS

    Program Acting As Both Server & Client

    807606
      Hello Everyone...

      I have a doubt. Consider, a program is having two threads. One is listening on port X, Say 1500. When the user interacts with the program's second thread, it gets data from some other machine on port X i.e., same 1500. is this possible ?

      Also..
      If this program is running in more number of machines...
      Is it possible that a program running as server can act as client for another server.. (On SAME port) ???

      Note: I have multiple threads to handling incoming requests for server. But, the Second thread (Client) is only one at a time..

      Please Help Me...

      Thanking you in advance..

      R. Kaja Mohideen
        • 1. Re: Program Acting As Both Server & Client
          807606
          Sure it is possible. Just Do It(tm)!
          • 2. Re: Program Acting As Both Server & Client
            807606
            When a program acts as a server it is "listening" for a request on a given port. When a program acts as a client, requesting services, it "targets" a given port on another (or even the same) machine. The client's socket (ipaddress:port pair) is independent of the server's socket, unless both the client and server are on the same ip address, in which case the ports must be different.
            Yes, a program can act as both a client and a server. As a matter of fact this is exactly what occurs in peer-to-peer data communications

            Prof. Cullen