• C

Recv: Transport Endpoint not connected


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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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)
jameswaltAuthor Commented:
I am implementing thread-based - does this matter?
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.