1 回答

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
- 1 回答
- 0 關(guān)注
- 398 瀏覽
添加回答
舉報(bào)