G
Guest
hi
i got one file transfer program using serialization which has a limitation
that i can send only 8192 bytes(8KB). i want to send more than that wht can i
do. how can i divide the file into mutiple segment and send the file and
receive it. here is the program below
public static void SendFileInfo()
{
// Get file type or extension
fileDet.FILETYPE = fs.Name.Substring((int)fs.Name.Length - 3, 3);
// Get file length (Future purpose)
fileDet.FILESIZE = fs.Length;
XmlSerializer fileSerializer = new XmlSerializer(typeof(FileDetails));
MemoryStream stream = new MemoryStream();
// Serialize object
fileSerializer.Serialize(stream, fileDet);
// Stream to byte
stream.Position = 0;
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, Convert.ToInt32(stream.Length));
Console.WriteLine("Sending file details...");
// Send file details
sender.Send(bytes, bytes.Length, endPoint);
stream.Close();
}
and in the receiving end
public static void ReceiveFile()
{
try
{
Console.WriteLine(
"-----------*******Waiting to get File!!*******-----------");
// Receive file
receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
// Convert and display data
Console.WriteLine("----File received...Saving...");
// Create temp file from received file extension
fs = new FileStream("temp." + fileDet.FILETYPE, FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite);
fs.Write(receiveBytes, 0, receiveBytes.Length);
Console.WriteLine("----File Saved...");
Console.WriteLine("-------Opening file with associated program------");
Process.Start(fs.Name); // Opens file with associated program
}
catch (Exception e)
{
Console.WriteLine(e.ToString ());
}
finally
{
//fs.Close();
receivingUdpClient.Close();
}
}
plz give solution for this
thanks for advance
lkr
i got one file transfer program using serialization which has a limitation
that i can send only 8192 bytes(8KB). i want to send more than that wht can i
do. how can i divide the file into mutiple segment and send the file and
receive it. here is the program below
public static void SendFileInfo()
{
// Get file type or extension
fileDet.FILETYPE = fs.Name.Substring((int)fs.Name.Length - 3, 3);
// Get file length (Future purpose)
fileDet.FILESIZE = fs.Length;
XmlSerializer fileSerializer = new XmlSerializer(typeof(FileDetails));
MemoryStream stream = new MemoryStream();
// Serialize object
fileSerializer.Serialize(stream, fileDet);
// Stream to byte
stream.Position = 0;
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, Convert.ToInt32(stream.Length));
Console.WriteLine("Sending file details...");
// Send file details
sender.Send(bytes, bytes.Length, endPoint);
stream.Close();
}
and in the receiving end
public static void ReceiveFile()
{
try
{
Console.WriteLine(
"-----------*******Waiting to get File!!*******-----------");
// Receive file
receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
// Convert and display data
Console.WriteLine("----File received...Saving...");
// Create temp file from received file extension
fs = new FileStream("temp." + fileDet.FILETYPE, FileMode.Create,
FileAccess.ReadWrite, FileShare.ReadWrite);
fs.Write(receiveBytes, 0, receiveBytes.Length);
Console.WriteLine("----File Saved...");
Console.WriteLine("-------Opening file with associated program------");
Process.Start(fs.Name); // Opens file with associated program
}
catch (Exception e)
{
Console.WriteLine(e.ToString ());
}
finally
{
//fs.Close();
receivingUdpClient.Close();
}
}
plz give solution for this
thanks for advance
lkr