Reserve a TCP port in Windows

后端 未结 5 1725
小鲜肉
小鲜肉 2021-02-01 23:14

I\'d like to reserve a TCP port, to be bound by a service later, so that Windows doesn\'t inadvertently use the same number when assigning random port numbers. I know this is po

5条回答
  •  庸人自扰
    2021-02-01 23:33

    I've come up with a possible solution, so I thought I may as well document it here as an answer.

    A process can pass a socket over to another process via a call to WSADuplicateSocket, so a coordinating process could bind to a dynamic port, and internally associate it with a given IPC name. When a ZMQ server process wanting to "bind" to that name arrives, the coordinating process copies the bound socket to the server process and closes its own copy.

    This solution doesn't address my preference to avoid calling bind(), but that may not be strictly necessary; I'll have to perform some tests.

提交回复
热议问题