
下面这段代码编译出来程序,运行在 Windows 下最多只有两并发(用 IDM 之类的工具下载文件,最多只能两线程,第三个会 hang 住)。 同样的代码运行在 Linux 下就没有这个问题。
package main import ( "flag" "log" "net/http" ) func main() { port := flag.String("p", "8022", "port to serve on") directory := flag.String("d", ".", "the directory of static file to host") flag.Parse() http.Handle("/", http.FileServer( http.Dir(*directory))) log.Printf("Serving %s on HTTP port: %s\n", *directory, *port) log.Fatal( http.ListenAndServe(":"+*port, nil)) } 1 Mohanson 2019-04-26 22:25:56 +08:00 via Android 试过直接用 curl 吗?我觉得有点不可思议… go 的 http 服务和客户端默认只保留 2 个长连接,但原则上是会自动扩容的 |