George Neuner writes:
> Multiple Racket applications *should* all be able to listen on the > same port without having been spawned from the same ancestor process. > If that isn't working now, something has gotten hosed. I don't know whether this used to work in the past or not, but currently only `SO_REUSEADDR' is set on TCP sockets: https://github.com/racket/racket/blob/60bf8f970e97caae391bfe919b78c370b2d01bdd/racket/src/rktio/rktio_network.c#L1427 I think we'd need to also set `SO_REUSEPORT', which is not available on all platforms, to support multiple processes listening on the same port without reusing file descriptors. Running a second instance of this program: #lang racket/base (require racket/tcp) (tcp-listen 9999 512 #t) (sync/enable-break never-evt) Currently fails with: tcp-listen: listen failed port number: 9999 system error: Address already in use; errno=48 context...: ... Greg Hendershott pointed out to me on Slack a while back that the `ffi/usafe/port' module could be used to bind sockets with custom options using the FFI and then convert them to ports, but I have yet to try that. > I'm not sure what you mean by "sharing" a listener, but using a > single listener with a pool of processing places actually is possible > (though tricky). I mean passing a `tcp-listener?' around between places so that each place can call `tcp-accept' on it. Something like this: #lang racket/base (require racket/place racket/tcp) (define ch (place ch (define listener (place-channel-get ch)) (tcp-accept listener) (place-channel-put 'ok))) (module+ main (define listener (tcp-listen 9999 512 #t)) (place-channel-put ch listener) (place-channel-get ch)) Currently, this fails with: place-channel-put: contract violation expected: place-message-allowed? given: #<tcp-listener> context...: ... My understanding is that there's nothing preventing this from working apart from the fact that no one's yet added support for this in the rktio layer. As you mentioned, though, even if this was supported we might run into other limitations when running many places at once. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/m24krkih6h.fsf%40192.168.0.142.