Re: select(), sending and receiving data



"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


.



Relevant Pages

  • Re: How to terminate a socket in CLOSE_WAIT state
    ... FTP Server fixed for certain FTP clients who use both passive ... This was causing a PASSIVE opened socket to be left ... but instead expect the "half close" from the receiver. ... this sends a TCP/IP FIN packet to the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to terminate a socket in CLOSE_WAIT state
    ... with the socket released within a few seconds of proper closure on both ... FTP Server fixed for certain FTP clients who use both passive ... but instead expect the "half close" from the receiver. ... this sends a TCP/IP FIN packet to the ...
    (microsoft.public.win32.programmer.kernel)
  • Re: timer and threading help needed
    ... running and you could tie your timer to that easily, ... My original C# app tuned a receiver over an RS232 port and the receiver ... buffer out over another socket back to the client. ... I have been unable to run my C# app on a win2003 server. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Applet Hangs when submitting data to servlet
    ... to put a time limit on my socket connections and socket reads. ... public void setTimeoutthrows UnknownHostException, ... on our web server. ... private JButton theSubmitButton_, theClearButton_; ...
    (comp.lang.java.programmer)