Error Code 10047 is WSAEAFNOSUPPORT:
Address family not supported by protocol family.
An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.
This means that something is wrong internally with the conversion of the TNetworkAddress to the TAddressUnion block used for the sockets call. Need to look into that hopefully somewhen this weekend. (Also I'm pretty sure when reading the code just now of ReceiveStr I've found a bug anyways)
To answer the other questions:
1. The ReceiveStr function does not have a parameter like TimeOut. So will it be blocked until a string come?
ReceiveStr does not read a string per-se, it will just read what is available and return this byte sequence as a string. With Datagrams it's rather simple because you'll just receive the contents of the last datagram as a string. With a Stream (TCP) it's a bit more complicated, because if you received multiple sends since the last receive, you'll just read everything the OS has buffered so far
2. I guess SetNonBlocking(sock, True) and ReceiveStrFromNonBlocking will check if there any data in the buffer, and it will return immediately if the buffer is empty, And then I need to implement timeout function by myself, Am I right?
Yeah if you want to deal with non blocking sockets. Otherwise look at these functions:
// Timeout in MS
{$IFDEF HAVE_SELECT_CALL}
function DataAvailable(const SocketArray: specialize TArray<TFPSocket>; TimeOut: Integer = 0): specialize TArray<TFPSocket>; overload;
function DataAvailable(const ASocket: TFPSocket; TimeOut: Integer = 0): Boolean; overload; //inline;
function DataAvailable(const SocketArray: array of TFPSocket; TimeOut: Integer = 0): specialize TArray<TFPSocket>; overload; inline;
{$ENDIF}
function BytesAvailable(const ASocket: TFPSocket): SizeInt;
I'm also pretty sure I made a test for it somewhere, but I'm not sure where 😅
3. How to enlarge the buffer size?
Do you mean the OS buffer? If so, fpsockets is just a very thin layer over the berkley sockets API. Not all functionalities are provided by it, and in those cases you just need to do the raw ioctl calls (or other apis). Just grab the FD field of the TFPSocket record and pass it to the system APIs.
Note: You can find a few more examples over here (it's the repository before I contributed it to fcl, so it may be slightly outdated):
https://github.com/Warfley/PasSimpleSockets/tree/master/examples