473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

huge Voice file transfer via TCP;

My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.

It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot

Sep 9 '06 #1
7 2283

You could split the bytes into blocks of 512KB.

const int bufferSize = xxx; // in bytes
for (int i = 0; i < bytes.Length; i += bufferSize)
{
int unsentCount = bytes.Length - startIndex;
int bytesToSent= (unsentCount >= bufferSize) ? bufferSize :
unsentCount;
StreamWriter.Write(bytes, startIndex, bytesToSent);
// may update progress or something here
}

fAnSKyer wrote:
My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.

It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot
Sep 9 '06 #2
There seem some mistakes since I coded by FireFox :)
Update a bit:

const int bufferSize = xxx; // in bytes
int unsentCount = bytes.Length;
int startIndex = 0
while (unsentCount 0)
{
int bytesToSent= (bufferSize < unsentCount) ? bufferSize :
unsentCount;
StreamWriter.Write(bytes, startIndex, bytesToSent);

// updating progress or something goes here

startIndex += bytesToSent;
unsentCount = bytes.Length - startIndex;
}

It might still have errors, but the idea is so.

Truong Hong Thi wrote:
You could split the bytes into blocks of 512KB.

const int bufferSize = xxx; // in bytes
for (int i = 0; i < bytes.Length; i += bufferSize)
{
int unsentCount = bytes.Length - startIndex;
int bytesToSent= (unsentCount >= bufferSize) ? bufferSize :
unsentCount;
StreamWriter.Write(bytes, startIndex, bytesToSent);
// may update progress or something here
}

fAnSKyer wrote:
My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.

It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot
Sep 9 '06 #3
but there will be several blocks, It may or may not happen that block A
sent before Block B but in receiving Block B came first, or part of? If
the net has problem it is quite possible. Thank you very much! :P

Truong Hong Thi wrote:
There seem some mistakes since I coded by FireFox :)
Update a bit:

const int bufferSize = xxx; // in bytes
int unsentCount = bytes.Length;
int startIndex = 0
while (unsentCount 0)
{
int bytesToSent= (bufferSize < unsentCount) ? bufferSize :
unsentCount;
StreamWriter.Write(bytes, startIndex, bytesToSent);

// updating progress or something goes here

startIndex += bytesToSent;
unsentCount = bytes.Length - startIndex;
}

It might still have errors, but the idea is so.

Truong Hong Thi wrote:
You could split the bytes into blocks of 512KB.

const int bufferSize = xxx; // in bytes
for (int i = 0; i < bytes.Length; i += bufferSize)
{
int unsentCount = bytes.Length - startIndex;
int bytesToSent= (unsentCount >= bufferSize) ? bufferSize :
unsentCount;
StreamWriter.Write(bytes, startIndex, bytesToSent);
// may update progress or something here
}

fAnSKyer wrote:
My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.
>
It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot
Sep 9 '06 #4
fAnSKyer <fa******@gmail.comwrote:
My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.

It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot
The first thing to note is that unless it's genuinely a text file, you
shouldn't be using StreamWriter to start with - you should be using
Stream.Write on an appropriate stream.

At that point, you should just write a buffer to the stream. Where are
you getting the data from? If it's a stream, you should have a buffer
of, say, 32K, and then just use something which reads data, then writes
out however much it reads to the destination stream, continuing until
it has no more left to read. *Don't* make the mistake of assuming that
every read will fill the buffer.

See http://www.pobox.com/~skeet/csharp/readbinary.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 9 '06 #5

Jon wrote:
fAnSKyer <fa******@gmail.comwrote:
My method is use big buffersize, 512KB [I dont know eventually how
large buffer can I have].
And use StreamWriter.Write(bytes, 0, bytes.Length) to transfer to
Server.

It works, however, because the test file is below 512KB, but when I
want transfer a bigger file, like 100M, what should I use? give me some
advice, Thanks a lot

The first thing to note is that unless it's genuinely a text file, you
shouldn't be using StreamWriter to start with - you should be using
Stream.Write on an appropriate stream.
Actually I use NetworkStream, -_-b I am sorry for my mistake

>
At that point, you should just write a buffer to the stream. Where are
you getting the data from? If it's a stream, you should have a buffer
of, say, 32K, and then just use something which reads data, then writes
out however much it reads to the destination stream, continuing until
it has no more left to read. *Don't* make the mistake of assuming that
every read will fill the buffer.

See http://www.pobox.com/~skeet/csharp/readbinary.html for more
information.
The url provides great help, Thanks.
But, if packet A send before packet B and because some reason, packet B
arrives first, and in the read client B is prior than A. if this is
possible? .NET can automaticly prevent this situation?
You know I have to transfer Voice Stream, and the order is important

Thanks a lot, MVP :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 10 '06 #6
"fAnSKyer" <fa******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
[...]
But, if packet A send before packet B and because some reason, packet B
arrives first, and in the read client B is prior than A. if this is
possible? .NET can automaticly prevent this situation?
Assuming you are using TCP (as your subject header suggests), then a) there
is no such thing as "packet A" and "packet B" as far as the network protocol
itself is concerned, and b) the data is guaranteed to arrive in the same
order in which it was sent.

It's not a .NET thing...it's imposed by TCP/IP.

Pete
Sep 10 '06 #7

Peter Duniho wrote:
"fAnSKyer" <fa******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
[...]
But, if packet A send before packet B and because some reason, packet B
arrives first, and in the read client B is prior than A. if this is
possible? .NET can automaticly prevent this situation?

Assuming you are using TCP (as your subject header suggests), then a) there
is no such thing as "packet A" and "packet B" as far as the network protocol
itself is concerned, and b) the data is guaranteed to arrive in the same
order in which it was sent.

It's not a .NET thing...it's imposed by TCP/IP.
Got it, Thanks a lot.
>
Pete
Sep 10 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Landley | last post by:
Dear Fellow Coders, I am attempting to send files using UDP. I had no problem sending small files, but when the files were over a certain size an exception was thrown. It was moaning about the...
3
by: Alessandro | last post by:
Hi all! I'm trying to write a file transfer application using TCP, but I'm having some problem to connect the client and the server. Sniffing with Ethereal I can see the packets sent from the...
10
by: George | last post by:
Hi, I have a report which shows all records from database into the browser. The final HTML comes out about 5 Meg. It takes 1 minute 5 seconds for transfer to show up when i hit the page with IE...
2
by: Chris | last post by:
Hi. I am trying to write a vb.net program to send large files via TCP. I was wondering if there was a code example or book that demonstrates how to write a simple file transfer program of large...
9
by: Sakharam Phapale | last post by:
Hi All, I want to read data from one file and write that into another file. Which is a way to do it quickly in terms of processing time? Data to be transfer is huge one. E.g. 2147483458...
2
by: Satish | last post by:
Hello...plz provide sample code on heo top transfer multiple files over a Local network VIA TCP/IP in .net
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
1
by: Saurabh | last post by:
Dear All, Can anyone tell me, how to write such a program that can transfer files (either binary or text) behind NAT devices( such as for computers behind firewalls and routers and other NAT...
9
by: NvrBst | last post by:
Whats the best way to count the lines? I'm using the following code at the moment: public long GetNumberOfLines(string fileName) { int buffSize = 65536; int streamSize = 65536; long...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.