Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SocketServer throws RuntimeException if already listening on this port #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
valzargaming opened this issue May 9, 2025 · 1 comment
Closed
Labels

Comments

@valzargaming
Copy link

valzargaming commented May 9, 2025

* @throws \RuntimeException if listening on this address fails (already in use etc.)

I am uncertain if a workaround is available for this as I haven't dove deeper into this repository, however I have a niche use-case where I have a game server running in another process which outputs http requests as webhooks to my instance of SocketServer. If the SocketServer goes offline at any point the game server which is making the calls to the SocketServer does not stop listening on whatever port the SocketServer was previously listening on, so if the SocketServer tries to restart it will fail to do so as it will be unable to rebind to the port.

This issue could be avoided when using a traditional Socket by simply utilizing the SO_REUSEPORT constant with socket_get_option, but so far I have not seen a way to do this with react/socket.

@valzargaming valzargaming changed the title SocketServer throws RuntimeException if already listening on this address fails SocketServer throws RuntimeException if already listening on this port May 9, 2025
@clue clue added the question label May 9, 2025
@clue
Copy link
Member

clue commented May 9, 2025

@valzargaming Got you, I think this is what you're looking for:

$socket = new React\Socket\SocketServer('[::1]:8080', [
    'tcp' => [
        'backlog' => 200,
        'so_reuseport' => true,
        'ipv6_v6only' => true
    ]
]);

From https://github.com/reactphp/socket#socketserver

I hope this helps! 👍 If so, consider supporting this project, for example by becoming a sponsor ❤️

@clue clue closed this as completed May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants