I want to send a file through TCP in golang. here's my server code:
c is connected *net.TCPConn
file, _ := os.Open(fn)
defer file.Close()
io.Copy(c, file)
// c.CloseWrite()
and client:
as above, c is connected *net.TCPConn
file, _ := os.Create("file.txt")
defer file.Close()
io.Copy(file, c)
my question is: in this way, the client can not receive the EOF of the file
so, io.Copy
blocked. I have to call c.CloseWrite
to notify client that the file is over.
If I want to send files, this will not work, How can I solve this?