libp2p/go-reuseport

reuse tcp/udp ports in golang

Go

807

203 commits

updated Aug 21, 2025

See the code

README

go-reuseport

GoDoc codecov Travis CI Discourse posts

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

// 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")
// 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

Project health

Overall

3.1/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

Latest release

v0.4.0 · Aug 17, 2023

Releases this year

0

Significant stargazers

bl-ue

458 followers · starred Jul 2026

Huang Huang

1,093 followers · starred Jan 2019

thxCode

62 followers · starred Feb 2024

Min Jin

350 followers · starred Apr 2019

libp2p/go-reuseport

reuse tcp/udp ports in golang

Go

807

203 commits

updated Aug 21, 2025

See the code

README

go-reuseport

GoDoc codecov Travis CI Discourse posts

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

// 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")
// 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

Project health

Overall

3.1/10

Maintained

0/10

Code review

3/10
OpenSSF Scorecard

Latest release

v0.4.0 · Aug 17, 2023

Releases this year

0

Significant stargazers

bl-ue

458 followers · starred Jul 2026

Huang Huang

1,093 followers · starred Jan 2019

thxCode

62 followers · starred Feb 2024

Min Jin

350 followers · starred Apr 2019