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 关注
- 346 浏览
添加回答
举报