Announcement

Collapse
No announcement yet.

TCP connection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • TCP connection

    At the moment I'm implementing a TCP server (DDT) in one of my programs. It needs to communicate with a third party client. (written in VC6). I'm testing at the moment with the echoserv and eclient examples. The problem:
    - Eclient -> Echoserv : OK.
    - Eclient -> VC6 test TCP server. : OK.
    - VC6 client -> VC6 TCP server. : OK.
    - VC6 client -> Echoserv : Does not work
    VC6 client returns: connection is refused. (application uses Port 21000)

    When I look with WinNT's netstat, it says that my TCP server listens on 71.31.1.1:21000 (my primary IP address), while the VC6 TCP server is said to listen on 0.0.0.0:21000 ???

    Why???

    -------------
    Peter.



    [This message has been edited by Peter Lameijn (edited June 24, 2000).]
    Regards,
    Peter

    "Simplicity is a prerequisite for reliability"

  • #2
    I've solved the above problem. It seems that while my TCP server listened on my primary IP address, the client was trying 127.0.0.1 .That raises another question: how do I setup a TCP server, if I don't know which IP address the client will use?
    (both programs run on the same machine, and I don't have any influence on the clients IP choice...)

    ------------------
    Peter.
    mailto[email protected][email protected]</A>
    Regards,
    Peter

    "Simplicity is a prerequisite for reliability"

    Comment


    • #3
      With the HOST ADDR statement you can retrieve the ip of the local machine. Then just use that number for both the server and the client. Or am I misunderstanding?

      ------------------
      Troy King
      [email protected]
      Troy King
      katravax at yahoo dot com

      Comment


      • #4
        Hi Peter

        the way to get a server to listen on all IP addresses is to bind() the server socket using %INADDR_ANY which has the value 0L.

        All my winsock code uses the winsock api directly so I don't know if it's possible to do it using the PB winsock encapsulation - I suspect not.

        Here's an example creating a server socket and binding it to an address:

        Code:
        FUNCTION PassiveSock( szService AS ASCIIZ , szTransport AS ASCIIZ, BYVAL lLen AS LONG) AS LONG
           LOCAL ptServent AS servent PTR
           LOCAL minsock_sa AS sockaddr_in
           LOCAL lSock AS LONG
           LOCAL lSockType AS LONG
        
           minsock_sa.sin_family = %AF_INET
           minsock_sa.sin_addr.s_addr = %INADDR_ANY
        
           'map service to port
           ptServent = getservbyname( szService, szTransport )
           IF ISTRUE( ptServent ) THEN
              minsock_sa.sin_port = htons( ntohs( @ptServent.s_port ) )
           ELSE
              minsock_sa.sin_port = htons( BYVAL VAL( szService ) )
              IF ISFALSE( minsock_sa.sin_port ) THEN
                 STDOUT "Can't retrieve service: " + szService
                 CALL WSACleanup()
                 FUNCTION = %INVALID_SOCKET
                 EXIT FUNCTION
              END IF
           END IF
        
           IF UCASE$(szTransport) = "UDP" THEN
              lSockType = %SOCK_DGRAM
           ELSE
              lSockType = %SOCK_STREAM
           END IF
        
           'socket allocation
           lSock = socket( %PF_INET, lSockType, 0 )
        
           IF lSock = %INVALID_SOCKET THEN
              STDOUT "Can't create socket"
              FUNCTION = %INVALID_SOCKET
              CALL WSACleanup()
              EXIT FUNCTION
           END IF
        
           'bind socket
           IF bind( lSock, minsock_sa, SIZEOF( minsock_sa) ) = %SOCKET_ERROR THEN
              STDOUT "Can't bind to port " + szService
              FUNCTION = %INVALID_SOCKET
              CALL WSACleanup()
              EXIT FUNCTION
           END IF
        
           IF ( lSock = %SOCK_STREAM AND listen( lSock, lLen ) = %SOCKET_ERROR ) THEN
              STDOUT "Can't listen on port: " + szService 
              FUNCTION = %INVALID_SOCKET
              CALL WSACleanup()
              EXIT FUNCTION
           END IF
        
           FUNCTION = lSock
        END FUNCTION
        Cheers

        Florent



        ------------------

        Comment


        • #5
          Thanks.

          Troy:
          I have no influence on the clients IP choice (third party program)
          Florent:
          I'm using the PB/DLL TCP xx functions, but I also don't know if it's possible this way to listen on all IP Addresses for a given port. If not, i'll have to go the API-way....

          ------------------
          Peter.
          mailto[email protected][email protected]</A>

          [This message has been edited by Peter Lameijn (edited June 24, 2000).]
          Regards,
          Peter

          "Simplicity is a prerequisite for reliability"

          Comment


          • #6
            Does anyone know if it's possible with TCP OPEN SERVER to let it listen for a given port on all IP addresses? (and not just on an address specified with ADDR xxxx)

            ------------------
            Peter.
            mailto[email protected][email protected]</A>
            Regards,
            Peter

            "Simplicity is a prerequisite for reliability"

            Comment

            Working...
            X