Answer the question
In order to leave comments, you need to log in
How to send message from server to client?
Hello!
There is a listener (goroutine) that listens for a connection with a client
. It has this:
var buffer = make([]byte, 1024)
for {
bytesRead, err := conn.Read(buffer)
if err != nil {
conn.Close()
return
}
var s = string(buffer[:bytesRead])
//тут всякие действия в зависимости от приходящих значений
}
Answer the question
In order to leave comments, you need to log in
In order to send something, someone on the other side must receive. Judging by your mistake, the client closes the connection, and then nothing can be sent. We must first teach the client not to break the connection, but to continue to wait for new data, then the problem will disappear
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question