How to send a message from the server to the client?

There is a listener (goroutine) that listens for the client connection
It is this:
var buffer = make([]byte, 1024)

 for {
 bytesRead, err := conn.Read(buffer)
 if err != nil {
 var s = string(buffer[:bytesRead])
 //there are all sorts of actions based on incoming values

Well goroutine listens to incoming data and produces the desired actions, and even writes to the socket in response
but in this cycle to take and something to vanish to the client, bypassing the waiting for data from it?
Or is it not?

When you try to write something to the socket queue, the script crashes with error writing to a closed connection.

I would appreciate the help!
April 4th 20 at 13:14
2 answers
April 4th 20 at 13:16
In order to have something to send, on the other side someone should take. Judging by your error, the client closes the connection, and then it does and nothing will send. We must first teach the client not to break the connection and continue to wait for new data, then the problem will disappear
Thanks, I will try! - rachael commented on April 4th 20 at 13:19
What is there to try then? Connect to the server any Telnet, it does not break the connection and send data to it, in console everything will be visible - Kaylah_Hil commented on April 4th 20 at 13:22
@Kaylah_Hil, Yes, in the end did. It was the client, it tore the connection for some reason. - rachael commented on April 4th 20 at 13:25
April 4th 20 at 13:18
Problem solved: in goroutine, which processed the requests from the client have caused another goroutine, which gave connexin. Thank you all who responded!

Find more questions by tags GoSockets