socket programming in C + multiple socket, same port num

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • boddah
    New Member
    • Dec 2008
    • 15

    socket programming in C + multiple socket, same port num

    Hi all,
    I was trying to create 2 sockets to be able to establish 2 connections to a client. The first socket supposedly to facilitate the DH algo which I wanted to implement and the second socket to only accept byte streams as input. I always get "unable to bind" even though I've used the close() and shutdown() function to close the first socket. Can anyone help show me the way here?
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Ususally shutdown shuld be called from server side and close from client side.
    As u cal shutdown you shuld be able to use the same port.

    Raghu

    Comment

    • boddah
      New Member
      • Dec 2008
      • 15

      #3
      Originally posted by gpraghuram
      Ususally shutdown shuld be called from server side and close from client side.
      As u cal shutdown you shuld be able to use the same port.

      Raghu
      Yes Raghul, I'm aware of that. But still I'm unable to bind the socket to the port.

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        After calling shutdown tru to run netstat and see whether the port is released or some other process is using that port.

        Raghu

        Comment

        • boddah
          New Member
          • Dec 2008
          • 15

          #5
          After creating the 1st socket, a client successfully connects to it and closed its connection. When the server tries to bind for the second socket, it fails and the app exits. Hence, the 2nd client unable to connect. Any way i can solve this?

          Comment

          • gpraghuram
            Recognized Expert Top Contributor
            • Mar 2007
            • 1275

            #6
            Hi,
            i am getting ur question.
            Usually after shutdown this behaviour dosent happen.
            So to understand whats happenening after running the first application run netstat and see whats happening to the port or somebody is using it.

            Then run the second program if the port is not used by any body.

            Raghu

            Comment

            • Peter Random

              #7
              I'm quite new to the use of sockets but I think this might have to do with the "TIME-WAIT" state (which often takes up to 4 minutes, and is there to deal with wandering packages etc.)

              Comment

              Working...