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

feat: add IPv6 support #39

Closed
wants to merge 9 commits into from

Conversation

italodeverdade
Copy link

@italodeverdade italodeverdade commented Aug 22, 2024

Hey, first of all thanks for the amazing project! :)

I'm implementing a python project using simple-websocket on Railway and realized that simple-websocket don't support IPv6 yet. So i took the time to change the AF_INET to AF_INET6. Following the documentation specifics about the differences between both it should enough to use just AF_INET6 for now :)

AF_INET6 sockets provide support for Internet Protocol version 6 (IPv6) 128 bit (16 byte) address structures. Programmers can write applications using the AF_INET6 address family to accept client requests from either IPv4 or IPv6 nodes, or from IPv6 nodes only.

Like AF_INET sockets, AF_INET6 sockets can be either connection-oriented (type SOCK_STREAM) or connectionless (type SOCK_DGRAM). Connection-oriented AF_INET6 sockets use TCP as the transport protocol. Connectionless AF_INET6 sockets use User Datagram Protocol (UDP) as the transport protocol. When you create an AF_INET6 domain socket, you specify AF_INET6 for the address family in the socket program. AF_INET6 sockets can also use a type of SOCK_RAW. If this type is set, the application connects directly to the IP layer and does not use either the TCP or UDP transport.

I could be wrong here, but prefer to open the PR here so we can may add support in future? Thanks!

@miguelgrinberg
Copy link
Owner

Couple of notes.

First, the async client would need to be changed to support the same functionality, and ideally with the same change in the constructor arguments.

Second, I'm thinking there is another possible way to handle this, which would involve calling getaddrinfo(host, port, type=socket.SOCK_STREAM) and letting the system decide itself between IPv4 and IPv6. The address_family would only be needed in case you want to force one type or the other. The getaddrinfo function returns the arguments to pass to the socket constructor and the connect call. WDYT?

@italodeverdade
Copy link
Author

italodeverdade commented Sep 17, 2024

Hey @miguelgrinberg, first sorry to take longer to work on your feedback. Work has been crazy these days 🥲

So, I have checked the async client but it seems it uses different implementation without the need to pass address_family there so i assume that the async client handles it automatically? I made the changes but to be honest in a moment it feels wrong so let me know if you really need it there :)

I fixed also a typo on extra_headers parameters.

@miguelgrinberg
Copy link
Owner

I have implemented a simpler solution based on getaddrinfo() as I described above. The choice between ipv4 or ipv6 is made by this call.

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

Successfully merging this pull request may close these issues.

2 participants