0

I've been working with the cross-platform Websocket client, based on the Indy TIdHTTP component, found here.

The client, TIdHTTPWebSocketClient, internally uses TIdWebSocketMultiReadThread; the latter creates a non-blocking socket (InitSpecialEventSocket method) by using Indy's GStack IOControl to access ioctl.

The code, downloaded from github, works for Windows, but failed on Android; FIONBIO had to be changed to $5421.

I'm currently unable to test on iOS, and wish to know if others have managed to get TIdHTTPWebSocketClient to work on this platform, and what value of FIONBIO should be used.

Thanks in advance.

CAnder
  • 127
  • 8

1 Answers1

2

FIONBIO applies to ioctlsocket() on Windows and ioctl() on POSIX.

On POSIX, you can alternatively specify the SOCK_NONBLOCK flag when creating a socket, or set the O_NONBLOCK flag on a socket using fcntl(F_SETFL).

Note that Indy does have an AOverlapped (non-blocking) parameter on the TIdStack.NewSocketHandle() and TIdStackBSDBase.WSSocket() methods, and a TIdStackBSDBase.SetBlocking() method, but they are not currently implemented for non-Windows platforms (code has been written for them, but has not been checked in).

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Hi Remy, thanks for the response. I'm wanting to try SOCK_NONBLOCK, but can't find it defined anywhere in the Source directory. I found a value of $04000 online, and tried: Posix.SysSocket.socket (IdIPFamily[Id_IPv4], Id_SOCK_STREAM or SOCK_NONBLOCK , Id_IPPROTO_IP), but returns -1. Can you tell me what the value of SOCK_NONBLOCK is, or where to find it? Thanks again. – CAnder Oct 30 '19 at 01:25
  • @CAnder I've seen `SOCK_NONBLOCK` defined as [`04000`](https://sites.uclouvain.be/SystInfo/usr/include/bits/socket.h.html) ([here too](https://www.go4expert.com/articles/sockets-c-tutorials-t24491/)), [`0x40000000`](https://chromium.googlesource.com/chromiumos/third_party/glibc-ports/%2B/926d329540c726f47a3793840d4a472c24c89c18/sysdeps/unix/sysv/linux/hppa/socket.h), [`0x800`](https://golang.org/pkg/syscall/), but nowhere as `0x04000`. – Remy Lebeau Oct 30 '19 at 02:22
  • Hi Remy, admittedly the value I found was also 04000; I preceded the value with '$' myself, so apologies. BTW, managed to get the fcntl option to work, so thanks again. – CAnder Oct 30 '19 at 02:34
  • @CAnder technically, `04000` in C++ is an octal literal, not a decimal literal. 04000 octal = 2048 decimal = 0x800 hex. [Delphi does not support octal literals](https://stackoverflow.com/questions/23214528/). – Remy Lebeau Oct 30 '19 at 04:29
  • Hi Remy, using $800 as SOCK_NONBLOCK worked, plus I didn't previously know about octal literals, so thank you for that too. I've decided to stick with fcntl, as O_NONBLOCK is explicitly defined for both Android and OSX in Delphi. – CAnder Oct 30 '19 at 05:45