transfering a file 
Author Message
 transfering a file

part of my app transfers a file from 1 computer to another across a network,
the client connects to the server and gets the size of the file,

the server then sends ( size/1024 ) full 1024 byte buffers to the client
followed by 1 ( size % 1024) buffer

on the same machine this works fine
but when i tried it across my lan it only worked in 1 direction, A to B but
B to A would result in the file being corrupt.

this is the send part for the full buffers:

for(int i = 0; i < fullBuffers; i++)
{
    frStream.Read(sendBuffer, 0, Common.FTBufferSize);

   connectedSock.Send(sendBuffer);

Quote:
}

so in an effort to find out where it was being corrupted, i added between
the read and send statements above, code to hash the buffer and display it
on the screen, this way i could see if both had the same data and identify
if it was a transmition error.

but this had the unexpected result of fixing the issue :-/

so i then replaced the hash with a sleep statement and this also fixed the
error:

for(int i = 0; i < fullBuffers; i++)
{
    frStream.Read(sendBuffer, 0, Common.FTBufferSize);

  System.Threading.Thread.Sleep(1);

  connectedSock.Send(sendBuffer);

Quote:
}

But i dont know why...

Can anyone explane why this is happening?

and if there is a better solution or a better way of doing it?



Fri, 17 Jun 2005 05:20:14 GMT  
 transfering a file
Spike,

    I would use the NetworkStream class here, passing in your connected
socket.  Use the Write methods in place of the call to the Send method, and
then call Flush in between every call to Write.

    Hope this helps.

--
          - Nicholas Paldino [.NET/C# MVP]


Quote:
> part of my app transfers a file from 1 computer to another across a
network,
> the client connects to the server and gets the size of the file,

> the server then sends ( size/1024 ) full 1024 byte buffers to the client
> followed by 1 ( size % 1024) buffer

> on the same machine this works fine
> but when i tried it across my lan it only worked in 1 direction, A to B
but
> B to A would result in the file being corrupt.

> this is the send part for the full buffers:

> for(int i = 0; i < fullBuffers; i++)
> {
>     frStream.Read(sendBuffer, 0, Common.FTBufferSize);

>    connectedSock.Send(sendBuffer);
> }

> so in an effort to find out where it was being corrupted, i added between
> the read and send statements above, code to hash the buffer and display it
> on the screen, this way i could see if both had the same data and identify
> if it was a transmition error.

> but this had the unexpected result of fixing the issue :-/

> so i then replaced the hash with a sleep statement and this also fixed the
> error:

> for(int i = 0; i < fullBuffers; i++)
> {
>     frStream.Read(sendBuffer, 0, Common.FTBufferSize);

>   System.Threading.Thread.Sleep(1);

>   connectedSock.Send(sendBuffer);
> }

> But i dont know why...

> Can anyone explane why this is happening?

> and if there is a better solution or a better way of doing it?



Sat, 18 Jun 2005 00:52:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Transfering Image Files in COM Calls

2. transfering file collection with sockets

3. assembling and transfering a packet (help please)

4. assembling and transfering a packet (help please)

5. Transfering gnome app. to win32

6. Program transfering from singleuser to multiuser mode.

7. Transfering Focus/redraw from a CTree to a CView

8. Request the code for transfering a byte used C througth serial print

9. a question about value transfering from a dll function

10. Transfering Data form DropDownList ...

11. Drawing to one DC and then transfering it to the CPaintDC

12. Transfering C++ Objects through the net using CSocket

 

 
Powered by phpBB® Forum Software