Find the answer to your Linux question:
Results 1 to 3 of 3
Hello Guys I have got some misunderstanding about socket and ip addresses and ports, connect and accept functionality. Would you please help me?! /------------------------------------/ Situation 1 We have host1 with ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    20

    Networking: socket, IP address and port??? Tricky situations!!!


    Hello Guys

    I have got some misunderstanding about socket and ip addresses and ports, connect and accept functionality.
    Would you please help me?!
    /------------------------------------/
    Situation 1
    We have host1 with 195.137.203.134 and host2 195.137.203.133

    Host1 listen on 1234 host2 connects (from port 49076) to host1
    Host2 has already set up connection with Host1 (195.137.203.134:1234 < - >195.137.203.133: 49076)
    Host1 continues listening on 1234 host2 tries to connect (from port 49076) to host1 once more

    What will happen in this situation?
    Will the new connection be set up? How will this two connection be distinguished?

    On Linux and Win32 platforms!!!

    Situation 2

    We have host1 with 195.137.203.134 and host2 195.137.203.133 and host3 195.137.203.135

    Host1 listen on 1234 host2 connects (from port 49076) to host1
    Host2 has already set up connection with Host1 (195.137.203.134:1234 < - >195.137.203.133: 49076)
    Host2 listen also on 49076 host3 connects (from port 1371 to host2

    What will happen in this situation?
    Will the new connection (195.137.203.133:49076 < - >195.137.203.135:1371 be set up?
    If so why it can happen otherwise what will happen?

    On Linux and Win32 platforms!!!

    Situation 3 (combining two mentioned before)

    We have host1 with 195.137.203.134 and host2 195.137.203.133 and host3 195.137.203.135

    Host1 listen on 1234 host2 connects (from port 49076) to host1
    Host2 has already set up connection with Host1 (195.137.203.134:1234 < - >195.137.203.133:49076)
    Host1 listen on 1234 host3 connects (from port 1371 to host1
    Host2 has already set up connection with Host1 (195.137.203.134:1234 < - >195.137.203.135:1371

    Host2 listen also on 49076 host3 connects (from port 1371 to host2
    Host3 listen also on 13718 host2 connects (from port 49076) to host3

    What will happen in this situation?

    On Linux and Win32 platforms!!!
    /-------------------------------/


    I do not know how connect from the same port maybe using the same socket twice or like that???

    Some one can say it is impossible and full of errors Some one can say it will works but Would you please give your understanding why on Linux and Win32 platforms!!!


    Thanks a lot guys in advance
    Any help will be appreciated

  2. #2
    Just Joined!
    Join Date
    Sep 2005
    Posts
    20
    I would like to make clear my questions

    I am familiar with stuff how server and client function and organized (from programmerís point of view)
    The questions are:

    Can connect()ion be made from same address and port twice successfully (one time connect() successfully once more successfully from same address and port) what will happen from programmerís point of view (sockets) ???

    Can connect()ing and accept()ing be made using same address and port at the same time what will happen from programmerís point of view (sockets) ???

    Some stuff about this I have found here
    http://www.omnetpp.org/listarchive/msg05234.php

    What do you think


    Please share your experience and understanding

  3. #3
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    The server side will issue a bind() and listen(), than perform accept() for each incoming connection. Each accept() gets its own channel, although the port number it's listening on is the same each time.

    The client side does the connect(), and I believe if you try two connect()s on the same port you'll get an address in use status (but SO_REUSEADDR may prevent this - I'm a little rusty on the specifics. )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •