Comments (3)
You can set Listen func and NListener like this:
package main
import (
"fmt"
"net/http"
"time"
"github.com/lesismal/nbio/nbhttp"
reuseport "github.com/libp2p/go-reuseport"
)
func onEcho(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(time.Now().Format("20060102 15:04:05")))
}
func main() {
mux := &http.ServeMux{}
mux.HandleFunc("/", onEcho)
engine := nbhttp.NewServer(nbhttp.Config{
Network: "tcp",
Addrs: []string{"localhost:8080"},
Listen: reuseport.Listen, // set reuseport listen
// NListener: 2, // how many goroutine to handle Accept for each addr, if not set, 1 goroutine by default
Handler: mux,
})
err := engine.Start()
if err != nil {
fmt.Printf("nbio.Start failed: %v\n", err)
return
}
defer engine.Stop()
<-make(chan int)
}
from nbio.
amazing! thx. u should put somewhere easier to find :D i cant believe i'm the first to ask this question
from nbio.
Some other users asked about reuseport before, but in Chinese:
#285 (comment)
#157 (comment)
I'll do some investment to provide more docs/faq, thx for your feedback bro!
from nbio.
Related Issues (20)
- just tested the performance of nbio tcp https on multicore system. it's great! but... how to do h2? HOT 1
- am i asking for a lot? pushing for tcp performance and nbios hit the mark but... HOT 18
- curious about the "total success" HOT 28
- how to increase the eventloop from the tls server example? HOT 5
- only 2,000 req/s with redis client example but using tls server example modification, i can get 25,000 req/s. what's wrong? HOT 2
- 请教大佬,在很短的时间里,向同一个conn推送多次数据 HOT 8
- 使用udp发送数据,会存在丢包! HOT 14
- Retract v1.5.4 HOT 6
- how to set so reuseport option for server? HOT 3
- 1.5.6 仍可能存在潜在bug HOT 34
- What is the principle of realizing 10 million connections to a single server? HOT 3
- WS客户端发送超高压缩率内容,可导致服务器OOM HOT 15
- onClose 没有调用 HOT 2
- InsecureSkipVerify=false的时候,无法进行TLS连接 HOT 7
- 请教下关于二进制数据压缩的问题 HOT 3
- LetsEncrypt HOT 2
- 大佬有交流群吗 HOT 4
- 关于nbio里,Conn结构体的小改动
- 关于nbio里,Conn结构体的小改动 HOT 2
- 双向的TLS验证通过后,在onWebsocket里,无法获取r.TLS HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbio.