mirror of
https://github.com/libp2p/go-reuseport.git
synced 2025-12-24 12:12:36 +08:00
2feef492232186b940334da295e8984c606d4f05
Bumps [github.com/pkg/errors](https://github.com/pkg/errors) from 0.9.0 to 0.9.1. - [Release notes](https://github.com/pkg/errors/releases) - [Commits](https://github.com/pkg/errors/compare/v0.9.0...v0.9.1) Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
go-reuseport
NOTE: This package REQUIRES go >= 1.11.
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
Languages
Go
100%