We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
My server is receiving connections from the front end just fine, but emitting messages doesn't seem work. Is there something wrong with my syntax?
Front end:
const API_URL = "http://localhost:3311/socket.io/" let socket = io.connect(API_URL, {transports: ['websocket']}) socket.on("chat-message", (data) => { console.log(data) appendMessage("other-message", data) }) inputForm.addEventListener("submit", e => { e.preventDefault() const message = inputBox.value socket.emit("client-message", message, (result) => { console.log(result) }) inputForm.reset() })
Back end:
socket.On(gosocketio.OnConnection, func(c *gosocketio.Channel) { fmt.Println("id:", c.Id(), "ip:", c.Ip()) c.Join("room") }) socket.On("client-message", func(c *gosocketio.Channel, message string) string { fmt.Println("message from id:", c.Id(), ":", message) c.BroadcastTo("room", "chat-message", message) return "message sent!" }) router.Handle("/socket.io/", socket)
The text was updated successfully, but these errors were encountered:
same issue
Sorry, something went wrong.
No branches or pull requests
My server is receiving connections from the front end just fine, but emitting messages doesn't seem work. Is there something wrong with my syntax?
Front end:
Back end:
The text was updated successfully, but these errors were encountered: