Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

when transfered file to client (from server) , show messbox and .... ---> via socet programing

$
0
0

hello all

i want to make "Transfer Larg File" using Socket Application . . . .

i made it and every thing is ok .

But I want, when the filetransferewascomplete,a messageindicating and Finally,NetworkStream is closed ...

part of my code:

public void SendFile(string remoteHostIP, int remoteHostPort, string longFileName, string shortFileName) { try { if (!string.IsNullOrEmpty(remoteHostIP)) { byte[] fileNameByte = Encoding.ASCII.GetBytes(shortFileName); byte[] fileData = File.ReadAllBytes(longFileName); byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length]; byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length); fileNameLen.CopyTo(clientData, 0); fileNameByte.CopyTo(clientData, 4); fileData.CopyTo(clientData, 4 + fileNameByte.Length); TcpClient clientSocket = new TcpClient(remoteHostIP, remoteHostPort); NetworkStream networkStream = clientSocket.GetStream(); networkStream.Write(clientData, 0, clientData.GetLength(0));

/// here is my Problem -- if ( ? ? ? ? ) {} networkStream.Close(); MessageBox.Show("file Received"); } else { MessageBox.Show("Error...1"); } } catch { MessageBox.Show("Error...2");




001001110101110


Viewing all articles
Browse latest Browse all 31927

Trending Articles