Re: select(), sending and receiving data
- From: "Alex Fraser" <me@xxxxxxxxxxx>
- Date: Mon, 26 Dec 2005 18:15:58 -0000
"Markus Pitha" <markus@xxxxxxxxxx> wrote in message
news:269d6$43b02c65$54705512$12599@xxxxxxxxxxxxxxxxx
> I tried the whole day to manage this problem, but nothing worked.
> I don't understand, how FD_SET is to use. FD_SET is something I have to
> set or not, but when I set it, how should I now, if the server sends
> data or not in this moment. It's only possible either to set
> FD_SET(sock, &readfds); or FD_SET(sock, &writefds); but never both. I
> don't understand the weird behaviour of the program, because anything
> must me wrong there. I still have to type at least one character to
> receive the message of the server. Then I'm able to type again.
> Usually I should immediately receive the message after the connection to
> the server.
The first select() call probably tells you that the socket is writeable but
not readable - the "welcome message" hasn't arrived yet. So you call
fgets(), which doesn't return until you press the return key. Then you call
send(), and go back round to select() which will now tell you the socket is
readable (and probably writeable too).
BTW, you don't set the socket to non-blocking mode. You should (use
fcntl()), although you'll usually not notice any problem unless you try to
send a significant amount of data faster than the receiver is receiving it.
Alex
.
- Follow-Ups:
- Re: select(), sending and receiving data
- From: Markus Pitha
- Re: select(), sending and receiving data
- References:
- select(), sending and receiving data
- From: Markus Pitha
- Re: select(), sending and receiving data
- From: Pascal Bourguignon
- Re: select(), sending and receiving data
- From: Markus Pitha
- select(), sending and receiving data
- Prev by Date: Re: select(), sending and receiving data
- Next by Date: IPV6 Fragmentation.
- Previous by thread: Re: select(), sending and receiving data
- Next by thread: Re: select(), sending and receiving data
- Index(es):
Relevant Pages
|