File shared C# code
FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
=======================
NetworkStream stream = client.GetStream();
if (flag == 1 && isConnected)
{
savePath = savePathLabel.Text + "\\" + fileName;
using (var output = File.Create(savePath))
{
// read the file divided by 1KB
var buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, bytesRead);
}
===================================
Byte[] bytes = new Byte[256];
String data = null;
int i;
// Loop to receive all the data sent by the client.
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
}
string[] msg = data.Split('@');
fileName = msg[0];
senderIP = msg[1];
senderMachineName = msg[2];
client.Close();
Comments
Post a Comment