第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Go 中創(chuàng)建多個(gè) http Server 實(shí)例不起作用

在 Go 中創(chuàng)建多個(gè) http Server 實(shí)例不起作用

Go
莫回?zé)o 2023-07-17 14:24:16
我正在嘗試在我的 go lang 應(yīng)用程序中創(chuàng)建 2 個(gè) HTTP 服務(wù)器,這就是我嘗試實(shí)現(xiàn)它的方法:package mainimport (    "net/http")func main() {    server := http.Server{        Addr:    ":9000",        //Handler:  http.HandleFunc("/", hello)    }    server.ListenAndServe()    server2 := http.Server{        Addr:    ":8000",        //Handler:  http.HandleFunc("/", hello)    }    server2.ListenAndServe()}我遇到的問(wèn)題是,當(dāng)我向?yàn)g覽器發(fā)出請(qǐng)求時(shí),它會(huì)發(fā)出http://localhost:9000/請(qǐng)求,但是當(dāng)我向?yàn)g覽器發(fā)出請(qǐng)求時(shí),http://localhost:8000/我收到“無(wú)法訪問(wèn)站點(diǎn)”。為什么我無(wú)法在 Go 中創(chuàng)建 HTTP 服務(wù)器的實(shí)例?
查看完整描述

1 回答

?
MMTTMM

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊

ListenAndServe阻塞一樣,第一個(gè)服務(wù)器啟動(dòng),但隨后不會(huì)繼續(xù)進(jìn)行第二個(gè)調(diào)用。解決這個(gè)問(wèn)題的一個(gè)簡(jiǎn)單方法是從server它自己的 goroutine 開(kāi)始,比如


func main() {


? ? server := http.Server{

? ? ? ? Addr:? ? ":9000",

? ? ? ? //Handler:? http.HandleFunc("/", hello)

? ? }

? ? go server.ListenAndServe()



? ? server2 := http.Server{

? ? ? ? Addr:? ? ":8000",

? ? ? ? //Handler:? http.HandleFunc("/", hello)

? ? }

? ? server2.ListenAndServe()


}


查看完整回答
反對(duì) 回復(fù) 2023-07-17
  • 1 回答
  • 0 關(guān)注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)