Recv: Transport Endpoint not connected

Posted on 2004-11-26
Last Modified: 2012-06-22

I have a client-server program. The client issues a connect on a TCP socket and the server issues a bind, listen, then accept.

When I try to receive a message from the client after successfully acknowledging the hostname of the client that has connected, the recv returns the following error:

recv: Transport endpoint not connected.

Any ideas on how to fix?
Question by:jameswalt
    LVL 23

    Expert Comment

    It sounds like you're trying to receive data before the connection is ready for that.

    Are you using the select() or poll() system call in your event loop to wait until one
    of the connections to your server is ready for read before you try to recv() the

    The typical order is..

    1. Socket(),  Bind(),  Listen() for each port before the event loop

    2. Select each port's fd for Read inside the event loop... when Read is YES, there is
        a connection waiting, issue Accept()
        Add connection to list

    3. Select each accepted connection and wait for Read when you expect to possibly receive
        information (i.e. always) select for Write as long as the server still has information waiting
        to be written to the client with send()
        (Stop selecting for Write after all information is sent)

    4.  Possibly select each client for Exception, though it might not always be clear what to do if a client's
         socket appears in the except set.

         On a user closed connection, typically you the socket gets selected for read, and the read() will return 0
         (Denoting EOF, end of connection)

    Transport End Point not connected may also be showing up if the client was disconnected at an inoportune moment
    for the server, like after it detected an attempted connection but before the accept() completed
    (Accept can fail with transport end point not connected)

    Author Comment

    I am implementing thread-based - does this matter?
    LVL 23

    Accepted Solution

    Certainly it matters, a thread based implementation is more complicated, at least
    if you have multiple server threads that need to deal with I/O.

    Each thread that does I/O needs to figure out when the connection or connections it is dealing with are ready
    to receive or send information, and handle it correctly, and usually this means each thread is in some I/O loop for most of
    its processing time (most real time will be spent waiting until the sockets are ready to recv() information that's been
    sent to you or send() information you're waiting to get out).

    What doesn't really change is the reason that you are getting the "transport end point not connected"

    It still likely means that the process is attempting an operation on a socket that it's not ready for yet

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now