Skip to content
Prev 61358 / 63421 Next

Question on non-blocking socket

Hi Ben,

For an easier experience with sockets, you may wish to have a look at the `nanonext` package. This wraps 'NNG' and is generally used for messaging over its own protocols (req/rep, pub/sub etc.), although you can also use it for HTTP and websockets.

In any case, a low level stream interface allows connecting with arbitrary sockets. Using something like `s <- stream(dial = "tcp://0.0.0.0:5555")` substituting in the actual address. This would allow you greater flexibility in sending and receiving over the bytestream without worrying so much about order and timing as per your current experience.

For example, a common pattern this allows for is doing an async receive `r <- recv_aio(s)`  before sending a request `send(s, "some request")`, and then query the receive result afterwards at `r$data`.

I won't go into too much detail here, but as it is my own package, please feel free to reach out separately via email or github etc.

Thanks,

Charlie