I am having trouble transferring a file to a client from a server program. A few problems I would like to address. First is that I make the byte array 6000 bytes big and its always that size. Is there a way to maintain the correct file size? Also with the way the code is now, the program hangs. It works when I take it out of the while loop on the client side. Help!!
Client:
private void button1_Click(object sender, EventArgs e)
{
BinaryWriter binWriter;
int i = -1;
Byte[] bytes = new Byte[6000];
NetworkStream clientStream = connTemp.GetStream();
byte[] outstream = Encoding.ASCII.GetBytes(txtMessage.Text);
clientStream.Write(outstream, 0, outstream.Length);
while (i != 0)
{
try
{
if (clientStream.CanRead)
{
i = clientStream.Read(bytes, 0, bytes.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
break;
}
}
binWriter = new BinaryWriter(File.Open("C:\\SeanLaunch\\log.rxlog",FileMode.Create));
binWriter.Write(bytes);
binWriter.Close();
}
}
Server:
Byte[] fileToSendAsByteArray = new Byte[6000];
fileToSendAsByteArray = File.ReadAllBytes("C:\\Launch\\Test.rxlog");
stream.Write(fileToSendAsByteArray, 0, fileToSendAsByteArray.Length);
EDIT!!!: I fixed the looping issue.