Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/libp2p/go-reuseport
reuse tcp/udp ports in golang
https://github.com/libp2p/go-reuseport
Last synced: 7 days ago
JSON representation
reuse tcp/udp ports in golang
- Host: GitHub
- URL: https://github.com/libp2p/go-reuseport
- Owner: libp2p
- License: isc
- Created: 2015-01-19T04:23:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-10T08:17:18.000Z (4 months ago)
- Last Synced: 2025-02-07T15:00:51.070Z (14 days ago)
- Language: Go
- Homepage:
- Size: 148 KB
- Stars: 779
- Watchers: 32
- Forks: 108
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-reuseport
[](https://protocol.ai)
[](https://godoc.org/github.com/libp2p/go-reuseport)
[](https://libp2p.io/)
[](https://webchat.freenode.net/?channels=%23libp2p)
[](https://codecov.io/gh/libp2p/go-reuseport)
[](https://travis-ci.org/libp2p/go-reuseport)
[](https://discuss.libp2p.io)This package enables listening and dialing from _the same_ TCP or UDP port.
This means that the following sockopts may be set:```
SO_REUSEADDR
SO_REUSEPORT
```This is a simple package to help with address reuse. This is particularly
important when attempting to do TCP NAT holepunching, which requires a process
to both Listen and Dial on the same TCP port. This package provides some
utilities around enabling this behaviour on various OS.## Examples
```Go
// listen on the same port. oh yeah.
l1, _ := reuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := reuse.Listen("tcp", "127.0.0.1:1234")
``````Go
// dial from the same port. oh yeah.
l1, _ := reuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := reuse.Listen("tcp", "127.0.0.1:1235")
c, _ := reuse.Dial("tcp", "127.0.0.1:1234", "127.0.0.1:1235")
```**Note: cant dial self because tcp/ip stacks use 4-tuples to identify connections, and doing so would clash.**
## Tested
Tested on `darwin`, `linux`, and `windows`.
---
The last gx published version of this module was: 0.2.2: Qme8kdM7thoCqLqd7GYCRqipoZJS64rhJo5MBcTpyWfsL9