× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Cool RPGLE,

Everything works as I expect except the receive part in the server... Rec() returns -1... and the error message says "Requested operation requires a connection"... Any clue why this happening?

Hang on, I'll ask my magic 8 ball. It said "Ask again later." Even my toys won't give me a straight answer. I guess I'll have to figure out my own answer to your question.

The error occurs when you try to call recv() on a socket that's defined as using a connection-oriented protocol such as TCP (AF_INET/SOCK_STREAM) but where the socket isn't connected.

Remember, in a server scenario, there are two (or more) sockets involved. One that listens for connections, and another is created each time you call accept().

Make sure you're calling recv() with the socket returned by accept(), and NOT the one that does the listening.

For example you start your server by doing this:

           s1 = socket(AF_INET: SOCK_STREAM: IPPROTO_IP);

           ... call bind() here ...
           ... call listen() here...

           s2 = accept(s1: *NULL: *OMIT);

The following statement will fail with ENOTCONN (CPE3438, "Requested operation requires a connection") because s1 isn't connected. (s2 is!)

           len = recv(s1: %addr(buf): %size(buf): 0);

However, the following should work fine:

           len = recv(s2: %addr(buf): %size(buf): 0);

Another thought... perhaps the program on the other end of the session has already closed the socket with the close() API? Depending on your TCP/IP settings, this could potentially cause the same error.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.