golang
func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello world", r.RemoteAddr)
}
golang
func IndexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello world", r.RemoteAddr)
}
ln, err := net.Listen("tcp", ":8080")
if err != nil {
// handle error
}
for {
conn, err := ln.Accept()
if err != nil {
// handle error
}
go handleConnection(conn)
}
官方文档有的,可以去看看
https://golang.org/pkg/net/
http.HandleFunc("/", IndexHandler)
Plugin.serve = &http.Server{
Addr: ":8080",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
ConnState: ConnStateListener,
}
panic(Plugin.serve.ListenAndServe())
ConnState 提供了conn的获取
7 回答5.3k 阅读
6 回答6.8k 阅读✓ 已解决
4 回答2.3k 阅读
1 回答3.4k 阅读
2 回答883 阅读✓ 已解决
2 回答2.2k 阅读
1 回答2.1k 阅读
使用http.Hijacker: