Hi, I used the socket functions a while ago for communication on the localhost via TCP. In the end we had best results with trying to connect first with hostname = NULL (which means connection on localhost) and then, if that failed (for whatever reason) on "localhost". I can't remember exactly why we decided so but somehow the code ended up like this. Since I never sent something back, I can only tell you about receiving.

For receiving, I used a global char string like this:

Code:
#define SOCKET_LEN 32
char g_chSocket [SOCKET_LEN];



because I received some text with encoded data, therefore I needed some more characters; and I needed to clear it before with strcpy and "". For the second parameter for socket_receive I choose SOCKET_LEN - 1, so 31 instead of 32 characters. I can't remember why, but I guess it is some string delimiter related thing. It is exactly the number of characters, because each character consumes a byte. To transform the received string, I copied it into a STRING* then, like this:

Code:
STRING* g_strSocket = "#32";

str_cpy(g_strSocket, g_chSocket);
str_trunc(g_strSocket, str_len(g_strSocket) - bytes);



for which bytes is the returned int value of socket_receive.