reading from a socket

S

Steve Richter

when a client reads from a socket, how does it know the server has
completed sending and is itself currently blocking on a read from the
client?

I am writing a small ftp client in C for the IBM AS400 using the UNIX
APIs. When the client code connects to the FTP server it reads back
the initial welcome messages. My code reads from the server, gets
some /r terminated messages. Reads again and gets more /r terminated
welcome messages. Then reads a 3rd time and blocks because there is
nothing more to read. What in the socket protocol tells me the 3rd
read is going to block?

thanks,
 
N

Noob

Steve said:
when a client reads from a socket, how does it know the server has
completed sending and is itself currently blocking on a read from the
client?

I am writing a small ftp client in C for the IBM AS400 using the UNIX
APIs.

Hello,

This is the wrong newsgroup. comp.unix.programmer is the group you want.

Regards.
 
B

BGB

ok. reposted on comp.unix.programmer

yep... because for who knows what reason, the people here generally
exclude/reject anything not related to the C standard, and most topics
related to actually using the language (which necessarily either involve
OS-specific details, or other details not directly revolving around the
C standard...).

in a way it is silly/stupid, but whatever...
 
J

John Gordon

In said:
yep... because for who knows what reason, the people here generally
exclude/reject anything not related to the C standard, and most topics
related to actually using the language (which necessarily either involve
OS-specific details, or other details not directly revolving around the
C standard...).
in a way it is silly/stupid, but whatever...

It is not "silly" to suggest that a discussion be taken to where the
experts are.

You can discuss retirement planning with your dentist, and he might
actually know something about it, but you'll likely get better advice
from a retirement palnner.
 
B

BGB

It is not "silly" to suggest that a discussion be taken to where the
experts are.

You can discuss retirement planning with your dentist, and he might
actually know something about it, but you'll likely get better advice
from a retirement palnner.

except when asking questions that are sufficiently generic to where most
people will know the answer (unless they live in a hole or
something...), or which are not strictly topical in any relevant newsgroup.

it is silly that people start waving "off topic" around as soon as the
conversation goes outside "well, the C standard says this..." and random
newbies doing Q/A about newbie issues related to the C standard ("why
cast pointer between incompatible types no work?...", ...).

the only real sane explanation is for volume control, but it smells like
many people have sticks shoved somewhere, which isn't really ideal...

much like people making a big fuss over "little detail not guaranteed by
the standard" even if "liable to work for any sane target one is
probably going to want to build their code for", or putting up a giant
fuss over "implementation details" related to how a given feature works
on a given target. AKA: "ultra-portability", where portability
requirements are assumed to extend beyond the N combinations of CPU and
OS which are the stated targets of a given program (for example, if a
program is only intended to be used on Windows on 32-bit x86, then picky
little thins about "well, relying on 8-bit chars may not work on some
esoteric embedded system"/... are not terribly relevant, since, after
all, the code is only intended to run on a single target anyways, but
issues about, say, behavior of WoW64/... may be relevant).


all of which are relevant to "actually using the language for writing
actual code", which itself isn't topical, since apparently it is a group
more for newbie Q/A than for anyone actually using the language for
anything.


or such...
 
K

Keith Thompson

BGB said:
yep... because for who knows what reason, the people here generally
exclude/reject anything not related to the C standard, and most topics
related to actually using the language (which necessarily either involve
OS-specific details, or other details not directly revolving around the
C standard...).

in a way it is silly/stupid, but whatever...

The question really is Unix-specific. comp.unix.programmer is an
active newsgroup, full of experts who know more about sockets than,
for example, I do. Steve will get *better answers* there than he
would here.

Why would you want him to post here instead?
 
B

BGB

The question really is Unix-specific. comp.unix.programmer is an
active newsgroup, full of experts who know more about sockets than,
for example, I do. Steve will get *better answers* there than he
would here.

Why would you want him to post here instead?

well, one can also post on other groups...
but, simply being like "OT here, go post over there" is not very
helpful, especially for something trivial, where someone could have just
responded:
"ok, go look up 'fcntl()' and O_NONBLOCK" or "ioctl() and FIONBIO" or
similar, which would presumably have been more helpful answers, and is
reasonably portable (which works on POSIX systems, and is "reasonably
similar" for Winsock, just with "ioctlsocket()" instead of "ioctl()", ...).

so, really, there is no reason to redirect, and a general answer could
have been given which would have extended to the vast majority of
existing operating systems...


it is about like redirecting someone to a different group for the
difference between '\\' and '/' as a path separator. it is silly and
pointless...

better is to try to give helpful responses, rather than having the
default answer be "OT here, go ask somewhere else...".


or such...
 
J

John Gordon

In said:
"ok, go look up 'fcntl()' and O_NONBLOCK" or "ioctl() and FIONBIO" or
similar, which would presumably have been more helpful answers, and is
reasonably portable (which works on POSIX systems, and is "reasonably
similar" for Winsock, just with "ioctlsocket()" instead of "ioctl()", ...).

It's kind of funny that, even in your own example, you had to detour
into system-specific details.
better is to try to give helpful responses, rather than having the
default answer be "OT here, go ask somewhere else...".

If ask my dentist about retirement planning, the most helpful answer he
can give me is "go talk to a retirement planner."
 
B

Ben Bacarisse

BGB said:
well, one can also post on other groups...
but, simply being like "OT here, go post over there" is not very
helpful, especially for something trivial, where someone could have
just responded:
"ok, go look up 'fcntl()' and O_NONBLOCK" or "ioctl() and FIONBIO" or
similar, which would presumably have been more helpful answers, and is
reasonably portable (which works on POSIX systems, and is "reasonably
similar" for Winsock, just with "ioctlsocket()" instead of "ioctl()",
...).

That does not answer the OP's question. Are you sure someone here would
know how to correct that reply? It's much more likely that such a
correction would happen in comp.unix.programmer.
so, really, there is no reason to redirect, and a general answer could
have been given which would have extended to the vast majority of
existing operating systems...

it is about like redirecting someone to a different group for the
difference between '\\' and '/' as a path separator. it is silly and
pointless...

better is to try to give helpful responses, rather than having the
default answer be "OT here, go ask somewhere else...".

Some answers might lead the OP astray. Almost by definition, the OP
does not know what the right answer is and a wrong one that goes
uncorrected might lead to all sorts of unnecessary convolutions in the
code.
or such...

Eh?
 
J

John Gordon

In said:
it is silly that people start waving "off topic" around as soon as the
conversation goes outside "well, the C standard says this..." and random
newbies doing Q/A about newbie issues related to the C standard ("why
cast pointer between incompatible types no work?...", ...).

You seem to be assuming that people *could* have answered the question
but chose not to, simply because it's off-topic for this group.

If a socket expert was reading this group and saw the question, I'm sure
they could have answered it and set the message headers so the answer
would appear here and also in a socket-appropriate group, and any further
discussion would then continue in that other group.

However, in the absence of such an expert, the best answer we can give,
and the answer we DID give, is to go ask somewhere else. Why is that so
bad?
 
B

BGB

That does not answer the OP's question. Are you sure someone here would
know how to correct that reply? It's much more likely that such a
correction would happen in comp.unix.programmer.

this was meant more as an example, not as a complete or comprehensive
answer to the OP, which would have taken actually writing something more
than a quoted expression.


well, the general answer for the matter of "ok, server stopped sending
stuff, how to deal with blocking?..." is "ok, set socket to non-blocking
mode, and just use non-blocking IO instead" (because normally
non-blocking IO is what is more useful anyways, as blocking for socket
IO is rarely a useful behavior...).

another possible answer is "select()", which can return a status for if
there is any data waiting in the socket, but IMO non-blocking IO is
generally more useful anyways (otherwise, how does one know the complete
message arrived before trying to read it?...).


actually, more generally, it makes sense to sit around waiting for
messages to arrive on a socket, and then to re-dispatch them in an
event-driven manner once complete and parsed (say, using callbacks or
similar).


Some answers might lead the OP astray. Almost by definition, the OP
does not know what the right answer is and a wrong one that goes
uncorrected might lead to all sorts of unnecessary convolutions in the
code.

whether or not the answer is ideal or not generally is not the issue,
more it is a matter of people declaring most everything OT here (and it
is not like people are "smarter" elsewhere, as most places on usenet is
flaming and trolls anyways...).

usual answer to most things is "hell, it works for now, good enough"
and, if sometime later, if it doesn't work, well either one can fix it
then, or be like "hell, not my problem". after all, most code is
released with a no-warranty clause, and it is peoples' own fault if they
use code in a way which compromises something without due-diligence, as
that clause is there for a reason...

say, if code is given out with a no warranty clause, and someone else
uses it in a place where (for example) it risks compromising peoples'
health or safety, it is the fault of the person who used the code in
such a context, and not the responsibility of the original developer.

although a person developing code for such a situation is likely
obligated to put in their best effort to ensure correctness and
reliability, but most people are not developing for such systems.


like, the goal is usually something like "throw something together, and
make it work", and the faster the work gets done, the happier most
people are (provided it works acceptably, as it looks bad to the bosses
or customers or similar if the code endlessly blows up in peoples'
faces, and may make the developer look bad...).

so, one saves time, and one saves money, thus hopefully avoiding the
problem of projects running over-schedule and over-budget.

granted, yes, a lot may come to priority weighting though, like if it is
more important that the code work reliably, one may exercise more
diligence, but for "run of the mill" stuff, it is more a "who cares"
scenario, except if the bugs are bad enough to get really annoying or
impede usability.

so, one can trade-off between whether saving time and reliability/... is
more of a priority.


also, I guess a certain level of effort needs to go into writing
"acceptable" code, since if the code is sufficiently poor as to
compromise maintainability or ones' ability to get the project done
effectively (within budget and schedule), then this may also risk eating
up time and money as well (again, looking bad to bosses, to customers,
or to investors, or similar...).


or such...
 
B

BGB

You seem to be assuming that people *could* have answered the question
but chose not to, simply because it's off-topic for this group.

If a socket expert was reading this group and saw the question, I'm sure
they could have answered it and set the message headers so the answer
would appear here and also in a socket-appropriate group, and any further
discussion would then continue in that other group.

However, in the absence of such an expert, the best answer we can give,
and the answer we DID give, is to go ask somewhere else. Why is that so
bad?

there was a delay of approx 5 minutes between the original post and the
"go elsewhere" comment.

this does seem a good amount like an automatic dismissal.


also, one doesn't have to be a "socket expert" in order to provide an
answer, as presumably nearly anyone who has run across the problem may
provide a reasonable answer, and it is not exactly like sockets are some
rare/esoteric topic.

it is like expecting there to be a "hash table expert" to provide
answers about when and where to use a hash table.


one could have also, for example, posted a link to online information
about the matter and possible solutions, drawing on the "expertise" of
others, ...

or such...
 
J

John Gordon

In said:
there was a delay of approx 5 minutes between the original post and the
"go elsewhere" comment.
this does seem a good amount like an automatic dismissal.

So... it's bad to answer questions quickly? I'm confused.
also, one doesn't have to be a "socket expert" in order to provide an
answer, as presumably nearly anyone who has run across the problem may
provide a reasonable answer, and it is not exactly like sockets are some
rare/esoteric topic.

You may be reading too much into my use of the term "expert". I simply
meant "someone qualified to answer the question."

Clearly, nobody fitting that description is reading this thread, so we
non-"experts" gave the best answer we could. Would you rather we stay
silent and leave the poor poster with no help at all?
it is like expecting there to be a "hash table expert" to provide
answers about when and where to use a hash table.

His question wasn't nearly that basic. He wasn't asking anything like
"when and where to use" a socket.
one could have also, for example, posted a link to online information
about the matter and possible solutions, drawing on the "expertise" of

Surely the poster has done basic online research himself already?
 
W

Willem

BGB wrote:
) well, the general answer for the matter of "ok, server stopped sending
) stuff, how to deal with blocking?..."

That was not the question.

) is "ok, set socket to non-blocking
) mode, and just use non-blocking IO instead" (because normally
) non-blocking IO is what is more useful anyways, as blocking for socket
) IO is rarely a useful behavior...).

So therefore that is not the answer.

) whether or not the answer is ideal or not generally is not the issue,
) more it is a matter of people declaring most everything OT here (and it
) is not like people are "smarter" elsewhere, as most places on usenet is
) flaming and trolls anyways...).

You obviously were not qualified to answer the question correctly,
given that you didn't even read the question correctly.

I'm not sure in what universe you live, but a wrong answer is *worse*
than no answer, and pointing somebody to where *correct* answers can
be found is *waay* better.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
B

BGB

So... it's bad to answer questions quickly? I'm confused.

except, that it was not an answer, it was a dismissal...

"go to this here other group" basically carries the subtext "screw off,
this topic is OT here...". saying something more politely does not
automatically nullify its original intent (nor does giving a gracious
response automatically mean that all is well). more just sort of some
strange social practice of candy-coating everything...

You may be reading too much into my use of the term "expert". I simply
meant "someone qualified to answer the question."

Clearly, nobody fitting that description is reading this thread, so we
non-"experts" gave the best answer we could. Would you rather we stay
silent and leave the poor poster with no help at all?

I gave a partial answer as an example elsewhere in the thread, which was
a comment about going and using non-blocking IO.

His question wasn't nearly that basic. He wasn't asking anything like
"when and where to use" a socket.

it was a "what do I do about this socket blocking?" issue, which is
close enough...

Surely the poster has done basic online research himself already?

potentially, but many people ask on usenet before going and bothering to
invoke the powers of Google or similar, or they are more just not
certain what keywords to plug in to summon the desired answer...
 
T

Tom St Denis

<snip>

You wrote 200 pages of text here and all you should have told them is
look up the select() function call. He could call select() monitoring
his read descriptors [sockets] and set a timeout if he wants to stop
waiting for data after a fixed amount of time.

Instead, you [incorrectly] ranted for 10 posts about how everything
should be topical here because us as programmers generally know things
like this. The original reply was correct to point it was OT and send
him to the other group.

Or, at the very least, if you're going to bother with the long
diatribe at least point the OP in the right direction instead of being
a monumentus jackass.

Tom
 
B

BGB

BGB wrote:
) well, the general answer for the matter of "ok, server stopped sending
) stuff, how to deal with blocking?..."

That was not the question.

) is "ok, set socket to non-blocking
) mode, and just use non-blocking IO instead" (because normally
) non-blocking IO is what is more useful anyways, as blocking for socket
) IO is rarely a useful behavior...).

So therefore that is not the answer.

) whether or not the answer is ideal or not generally is not the issue,
) more it is a matter of people declaring most everything OT here (and it
) is not like people are "smarter" elsewhere, as most places on usenet is
) flaming and trolls anyways...).

You obviously were not qualified to answer the question correctly,
given that you didn't even read the question correctly.

I'm not sure in what universe you live, but a wrong answer is *worse*
than no answer, and pointing somebody to where *correct* answers can
be found is *waay* better.

seemed correct enough to me...

FTP sends messages on lines, and then lines stop showing up when they
stop showing up. obvious answer: using non-blocking IO. then the program
doesn't block when it tries to read, and so can carry on its business...

shouldn't be so difficult.
 
B

BGB

<snip>

You wrote 200 pages of text here and all you should have told them is
look up the select() function call. He could call select() monitoring
his read descriptors [sockets] and set a timeout if he wants to stop
waiting for data after a fixed amount of time.

Instead, you [incorrectly] ranted for 10 posts about how everything
should be topical here because us as programmers generally know things
like this. The original reply was correct to point it was OT and send
him to the other group.

Or, at the very least, if you're going to bother with the long
diatribe at least point the OP in the right direction instead of being
a monumentus jackass.

interesting... (I guess it is notable how things can be seen differently
by different people...).

sorry it came off this way, just it was my response to what seemed to be
a sort of common social-injustice.

but, anyways, unless there is something worthwhile, I will probably end
this argument, as all this is not being terribly productive...
 
J

John Gordon

In said:
"go to this here other group" basically carries the subtext "screw off,
this topic is OT here...". saying something more politely does not

I don't think it carries that subtext at all. Instead it says, "We can't
answer your question, but those guys over there might know the answer."
I gave a partial answer as an example elsewhere in the thread, which was
a comment about going and using non-blocking IO.

And that was in fact a wrong answer, as someone else (an "expert"!)
answered that the real problem was the the poster wasn't following the
FTP message protocol correctly. It had nothing to do with blocking.

So we see first-hand the danger of answering technical questions when you
don't really know the answer -- and possibly don't even understand the
question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top