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

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

Gorilla Websocket:WebSocket 握手期間出錯:意外響應(yīng)代碼:404

Gorilla Websocket:WebSocket 握手期間出錯:意外響應(yīng)代碼:404

Go
慕絲7291255 2022-06-21 16:12:48
我克隆了 gorilla websocket 聊天示例并將其更新為使用多個(gè)房間。但是,我收到錯誤消息: Error during WebSocket handshake: Unexpected response code: 404 每當(dāng)我嘗試建立連接時(shí)在 chrome 中。我的源代碼在github上可用。它與原始示例非常相似,只是略有改動。我不知道為什么它不起作用。編輯:問題出現(xiàn)在這行代碼中:for _, name := range []string{"arduino", "java", "go", "scala"} {    room := newRoom("go")    http.Handle("/chat/go", room)    go room.run()}循環(huán)切片會導(dǎo)致 httphandle 函數(shù)出現(xiàn)問題。相反,我單獨(dú)聲明它們:room := newRoom("go")http.Handle("/chat/go", room)go room.run()...有用。我怎樣才能解決這個(gè)問題?
查看完整描述

1 回答

?
精慕HU

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

所以實(shí)際上從你的index.html文件中,你連接到錯誤的 url


<!-- index.html -->

<script>

    var serviceLocation = "ws://0.0.0.0:8080/chat/";

.....


    function connectToChatserver() {

        room = $('#chatroom option:selected').val();

        wsocket = new WebSocket(serviceLocation + room);

        // it connect to /chat/<room>, it has slash after chat

這是您的網(wǎng)址main.go


    http.Handle("/chat"+name, room)

它會使 url 像這樣:http://localhost:8080/chatgo,而不是你想要的:http://localhost:8080/chat/go


Fyi,它會因?yàn)槟銢]有正確處理而出錯channel,所以在我發(fā)送1條消息后,它會自動關(guān)閉。但這是另一個(gè)話題。


2020/08/04 06:42:10 running chat room java

2020/08/04 06:42:10 running chat room go

2020/08/04 06:42:10 running chat room arduino

2020/08/04 06:42:10 running chat room scala

2020/08/04 06:42:15 new client in room arduino

2020/08/04 06:42:15 client leaving room arduino

2020/08/04 06:42:15 client leaving room arduino

panic: close of closed channel


goroutine 6 [running]:

main.(*Room).run(0xc00007ac90)

        /home/fahim/Projects/Golang/go-chat/room.go:70 +0x3b5

created by main.main

        /home/fahim/Projects/Golang/go-chat/main.go:17 +0x2bd

exit status 2


查看完整回答
反對 回復(fù) 2022-06-21
  • 1 回答
  • 0 關(guān)注
  • 398 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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