What reasons would SDLNet_TCP_Send block for?

Ok, thanks a lot.
That’s a relief :)> Date: Sun, 7 Jun 2009 19:08:31 +0100

From: brian.ripoff at gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] What reasons would SDLNet_TCP_Send block for?

Hi.

TCP stands for Transmission Control Protocol. This means that it tries
to limit the amount of data on the network to a manageable size, one
that the receiver and the network itself can deal with. Part of the
protocol is negotiating a “sliding window”, the amount of data that
TCP allows on the network. Part of determining this window size is the
receiver - it will advertise their receive window (the size of the
buffer on the receiving socket), and the sender basically agrees to
not send more than that amount data. If the sending program tries to
send more data, TCP will block it until it receives some
acknowledgements from the receiver.

TCP uses timeouts, so if the receiver is judged to be inactive then a
send() operation will eventually return an error. You should never get
an infinite block, but you can get very long ones (relative to what
your program wants to do).

With raw sockets, it is possible to place them into a "non-blocking"
mode, which means that any operation which you try that would block
instead returns an error “this operation will block right now”. This
allows your program to continue processing without using multiple
threads (a thread per client can be expensive way of networking). The
current SDL_Net API does not expose this functionality.

As for server sockets, their only purpose is to act as a sort of
"factory" for actual connections. It doesn’t send or recv and
information itself. So with a server socket you use
SDLNet_TCP_Accept() and then use the SDLNet_TCP_Send() and
SDLNet_TCP_Recv() functions on the accepted socket.


More than messages?check out the rest of the Windows Live?.
http://www.microsoft.com/windows/windowslive/

I am trying to make a mail client with SDL_net. Usign SMTP protocol.
I am receiving first message from server : Server : 220 mx.google.com ESMTP y7sm10123479wjw.16 - gsmtp
then I try to send message to server using : SDLNet_TCP_Send(client, (void *)buffer, len)
After this, i dont receive any more messages from server, using : SDLNet_TCP_Recv(sock, bufferResponse, maxCharsRecieved), just blocks the program, it never returns from this function call. Can some one help?

Doing a recv on a socket, by it’s nature, blocks until data is actually
received. You need to look into SDL_net socket sets
https://www.libsdl.org/projects/SDL_net/docs/SDL_net.html#SEC41, which
will let you check sockets before doing a recv on them.

For a much better explanation on why recv blocks, check out Beej’s Guide to
Network Programming http://beej.us/guide/bgnet/, which is hands down the
most readable and educational guide about cross-platform network
programming. There are a few translations, too, if English is not your
primary langnuage.

-AlexOn Sun, Apr 26, 2015 at 4:18 AM, zellJunior <ostafi_ion at yahoo.com> wrote:

I am trying to make a mail client with SDL_net. Usign SMTP protocol.
I am receiving first message from server : Server : 220 mx.google.com
ESMTP y7sm10123479wjw.16 - gsmtp
then I try to send message to server using : SDLNet_TCP_Send(client, (void
*)buffer, len)
After this, i dont receive any more messages from server, using :
SDLNet_TCP_Recv(sock, bufferResponse, maxCharsRecieved), just blocks the
program, it never returns from this function call. Can some one help?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org