Send / receive file over TCP [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: TcpClient send data and receive data over network Loop until TcpClient response fully read I am trying to send a file from a server to a client over TCP. Server-side code, sending file: NetworkStream netStream = client.GetStream(); FileStream fs = new FileStream("usb.exe",FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data,0, data.Length); fs.Flush(); fs.Close(); netStream.Write(data