Skip to content
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

how to set SO_REUSEADDR Socket Option in libwebsockets? #3284

Open
pppaulpeter opened this issue Nov 25, 2024 · 2 comments
Open

how to set SO_REUSEADDR Socket Option in libwebsockets? #3284

pppaulpeter opened this issue Nov 25, 2024 · 2 comments

Comments

@pppaulpeter
Copy link

Hi Andy,

i got this error when i recreated the vhost by lws_create_vhost with the same port different tls certification in lws version 4.3
E: [null wsi]: lws_socket_bind: ERROR on binding fd 266 to port 7683 (-1 98)
E: [vh|4|websockets||7683]: lws_create_vhost: init server failed
E: Failed to recreate WebSocket vhost

should i wait some time to call lws_create_vhost or could i set SO_REUSEADDR Socket Option somehow? thanks! @lws-team

@lws-team
Copy link
Member

How is that going to help? If you open two different listening sockets on the same port, what is the OS supposed to do so that stuff for socket a gets seen by socket a and not b?

Lws can handle multiple vhosts listening on the same socket at the same port. You must ensure the .name of each vhost is different, and matches what would be seen at the host: header. Eg, warmcat.com and libwebsockets.org are vhosts that both exist at :443. routing to which vhost is handled after seeing which host the connecting client actually wanted. Then the right certs are passed back and it is hooked up to the correct logical vhost.

@pppaulpeter
Copy link
Author

pppaulpeter commented Nov 26, 2024

How is that going to help? If you open two different listening sockets on the same port, what is the OS supposed to do so that stuff for socket a gets seen by socket a and not b?

Lws can handle multiple vhosts listening on the same socket at the same port. You must ensure the .name of each vhost is different, and matches what would be seen at the host: header. Eg, warmcat.com and libwebsockets.org are vhosts that both exist at :443. routing to which vhost is handled after seeing which host the connecting client actually wanted. Then the right certs are passed back and it is hooked up to the correct logical vhost.

Hi Andy,

sorry for misunderstanding, i have destroy the last vhost before recreated the vhost by lws_create_vhost with the same port. Sometime i got this error even i have slept 5 seconds before recreated the vhost(destroy the vhost--------sleep 5 seconds---------create vhost with the same port). @lws-team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants