my problem is :
i make two programs one server and the second as client the client send files to server but when he receive it the size of received file is bigger than the sent file .
and thats the sent code
private void send_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"c:\\file11.wav", FileMode.Open, FileAccess.Read);
byte[] data= new byte[fs.Length];
fs.Read(data, 0, data.Length);
sck.Send(BitConverter.GetBytes(data.Length), 0, 4, 0);
sck.Send(data);
}
and at receiving we have this code
FileStream fs = new FileStream(@"c:\\jj.wav", FileMode.Create, FileAccess.Write);
sckt = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sckt.Bind(new IPEndPoint(0,08));
sckt.Listen(1);
acc = sckt.Accept();
sckt.Close();
new Thread(() =>
{
while (true)
{
byte[] sizebuffer = new byte[4];
acc.Receive(sizebuffer, 0, sizebuffer.Length, 0);
int size = BitConverter.ToInt32(sizebuffer, 0);
while (size > 0)
{
byte[] buffer;
if (size < acc.ReceiveBufferSize)
{
buffer = new byte[size];
}
else
buffer = new byte[acc.ReceiveBufferSize];
int rec = acc.Receive(buffer, 0, buffer.Length, 0);
size -= rec;
if (size < 0)
{ size = 0; }
fs.Write(buffer, 0, buffer.Length);
}
if any one can help me plz i ll be so glade