473,396 Members | 1,804 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,396 software developers and data experts.

size limit for byte array?

Ron
Hello,

I am trying to read a list of files from an FTP server
(mainframe) to a byte array using sockets as follows, but
not getting all the files in a given directory:

private readonly static int BUFFER_SIZE = 3300;
private byte[] buffer = new byte[BUFFER_SIZE];
private Encoding ASCII = Encoding.ASCII;

Socket socket = null;
int bytes;
string temp = "";

socket = CreateDataSocket(); //get connection here
SendCommand("NLST " + mask);

//while(true){

Array.Clear(buffer, 0, buffer.Length);
bytes = socket.Receive(buffer, buffer.Length, 0);
temp += ASCII.GetString(buffer, 0, bytes);
Console.WriteLine(temp);

//if( bytes < buffer.Length) break;
//}

I was originally looping in a while loop but got less than
if I just increased BUFFER_SIZE and just picked up
whatever temp would hold in one pass. At 3300 I get 2900
bytes worth of data. At 4096 I still only get 2900 or so
bytes of data into temp. There are about 5000 bytes of
data in this directory. What can I do to get all the
bytes of data into temp?

Thanks,
Ron

Nov 16 '05 #1
2 8293
Ron wrote:
Hello,

I am trying to read a list of files from an FTP server
(mainframe) to a byte array using sockets as follows, but
not getting all the files in a given directory:

<snip>

Sockets are streaming in nature, and while you might create a 16KB byte
array on one end and send off using 1 statement, you're not really
guaranteed to get it back in one call to Receive on the other end.

For all you know, you can get any number of blocks of data, ranging from
1 byte and upwards in size.

Instead of breaking the loop on "less than full buffer", try breaking it
on "empty buffer".

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #2
Lasse Vågsæther Karlsen <la***@vkarlsen.no> wrote:
I am trying to read a list of files from an FTP server
(mainframe) to a byte array using sockets as follows, but
not getting all the files in a given directory:

<snip>

Sockets are streaming in nature, and while you might create a 16KB byte
array on one end and send off using 1 statement, you're not really
guaranteed to get it back in one call to Receive on the other end.

For all you know, you can get any number of blocks of data, ranging from
1 byte and upwards in size.

Instead of breaking the loop on "less than full buffer", try breaking it
on "empty buffer".


And after doing that, try using a StringBuilder instead of string
concatenation - the current implementation will become horribly slow if
you get a large file.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

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

Similar topics

2
by: Jéjé | last post by:
Hi everyone. I'm currently implementing a Cache system. Limiting its capacity with the number of object makes no sense, since objects can have any size they want. So I'd like to limit its...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
1
by: Jón Sveinsson | last post by:
Hello everyone I have been trying to read and write struct to binary files, I'm using to functions to convert the struct to bytes and bytes to struct, I always receive the following error ...
3
by: spielmann | last post by:
Hello I want to change the scrollbar size of windows, How can I do that with vb.net I have find this in VB6 but how can we convert simply this code. thx
5
by: Gerrit | last post by:
Hi all, I'm getting an OutOfMemoryException when I initialize a byte array in C# like this: Byte test = new Byte; I'm using ASP.NET 2.0. In ASP.Net 1.1 it works fine. So what am I doing
2
by: Harry | last post by:
Good Day To all, When i am declaring a array for e.g char ....it means i am declaring array of 45 characters each of which has a maximum,minimum value limit or range...for example in...
2
by: D. Susman | last post by:
Hi, I know that this issue is indeed strictly operating system dependent but I am just curious: I have a five dimensional array, whose size sums to 68 MB (almost). This array is contained by...
10
by: Chunekit Pong | last post by:
I have a BYTE array - BYTE const* pbBinary I would like to know how many bytes in that byte array but if I do - sizeof(* pbBinary); - then I got 1 but if I do - sizeof( pbBinary); - then I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.