1 回答

TA貢獻1845條經驗 獲得超8個贊
所以實際上從你的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
這是您的網址main.go
http.Handle("/chat"+name, room)
它會使 url 像這樣:http://localhost:8080/chatgo,而不是你想要的:http://localhost:8080/chat/go
Fyi,它會因為你沒有正確處理而出錯channel,所以在我發送1條消息后,它會自動關閉。但這是另一個話題。
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 關注
- 401 瀏覽
添加回答
舉報