Skip to content

Instantly share code, notes, and snippets.

@tidwall
Created March 18, 2018 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tidwall/09eeff843e2f2e691f8361c00dcc00ab to your computer and use it in GitHub Desktop.
Save tidwall/09eeff843e2f2e691f8361c00dcc00ab to your computer and use it in GitHub Desktop.
Evio with SO_REUSEPORT

Evio with SO_REUSEPORT

Using the reuseport branch of evio, you can now provide an SO_REUSEPORT address options from the Serve function.

evio.Serve(events, "tcp://0.0.0.0:5000?reuseport=true")

This allows for multiple process/threads/goroutines to share the same address+port.

You can try it out using the echo example. Run this in seperate terminals:

go run examples/echo-server/main.go -reuseport -trace

Then repeatedly send a packet from a different computer:

echo hello | nc hostaddr 5000

You should see the message "hello" print to one of the two server consoles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment