Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Problems in C# TCP/IP transferring

Options
  • 03-09-2005 1:09am
    #1
    Closed Accounts Posts: 4,943 ✭✭✭


    I'm having problems transferring files over a network stream using C#. No matter what i seem to try, the transfer seems to max out at about 130kB/sec.

    I've tried the following:

    1) Greating a socket. Binding that socket to a networksteam. Directly reading the data byte by byte using Stream.ReadByte() from the networkstream.

    2) I bound the above networkstream to a BinaryReader, and using binaryreader.ReadBytes() to read the whole stream in one go.

    3) Placing a buffered stream on top of the network stream, and then placed a binaryreader on top of the buffered stream and read the data from the binary reader.

    4) Creating a TCP/Client, binding its stream to a networkstream and doing the above.

    5) Doing step four, and setting the recievebuffer of the TcpClient to be slightly larger than the file to be recieved.

    Thing is, no matter what i try performance seems to be quite slow when recieving files. If i download a file from a source in DC++, i can max out my connection at 200+ kB/sec. However if i download the same file in my program, i max out at about 135kB/sec.

    Can anyone show me working code on the best way to recieve a file in C# over TCP/IP? The data is being sent as a raw byte array. But no matter what i do, i can't seem to get better performance than 135kB/sec (max).


Comments

  • Registered Users Posts: 131 ✭✭theexis


    Not directly answering your question but you should consider:

    1. Compressing / Decompressing blocks of data over the wire (Zip is directly supported in new 2.0 framework)

    2. Use asyncronous sockets which directly related to the completion port architecture in WindowsNT for most efficient use of the platform

    3. Break file into chunks and start async transfer of multiple parts simultaneously

    4. Ensure you're not transitioning into kernel mode too often (async should help this), e.g. #1 above could be calling down into a kernel driver for each byte depending on how your network stack is constructed which is extremely costly.


Advertisement