473,511 Members | 14,052 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Question

AA
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could
be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot
Nov 15 '05 #1
6 2859
TCP is stream based, which means, it doesn't really distinguish between one
big blob of 10MB or 10 blobs of 1MB each or even 1.05million blobs of 1 byte
each.

The reason why "B" might be a good idea is you will put lesser pressure on
your memory manager.

-vJ

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #2
cs
there could also be a slowdown if you send too few bytes at once. I used to
have an upload app on c# that if I read one byte at a time from a file and
uploaded it it would run slow, then started tweaking it, sending 1024 bytes,
tehn 2048 (note the numbers dont have to be that, its just some common
numbers to try), I think up to 2048 I would see the speed increase after
that I wouldnt see it increase, it even decreased when I tried something
like 16384 or more.

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP12.phx.gbl...
TCP is stream based, which means, it doesn't really distinguish between one big blob of 10MB or 10 blobs of 1MB each or even 1.05million blobs of 1 byte each.

The reason why "B" might be a good idea is you will put lesser pressure on
your memory manager.

-vJ

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function
B) create small arrays with less data and send each one by one (which

could
be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot


Nov 15 '05 #3
You probably want to send in MTU size chunks (i.e. the lowest MTU in the
path). This can make IP more efficient at both ends. I would not suggest
building a 10MB byte array. The network stack breaks down into max datagram
buffers anyway, so larger then max datagram does not really help here.

--
William Stacey, MVP

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #4
B, definitely.

You can do something like "A", but it means you're allocating a big chunk of
memory, which is expensive (both in memory use and perf, since you will
flush your cache away when you traverse it). There's also the disadvantage
of having the receiver block on a read for a *long* time (could be 3 minutes
to send 10MB over a 10Mbps ethernet link (assuming I did my math
correctly)). You also might want to be able to restart the transfer if it
got interrupted for some reason.

Finally, the data is going to be chunked into smaller pieces when it goes
over the network anyway. My advice is to pick something reasonable
(something like 4K seems like a good starting point), and then benchmark to
see whether that's a good choice.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #5
Hi,

"AA" <aa@personal.net.py> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)
Create one small array and reuse it for each send.

The maximum bytes you can send at once, is the size of the underlying send
buffer.

You can get the size of the send buffer by calling GetSocketOption with
SocketOptionName.SendBuffer. This is what TcpClient.SendBufferSize property
does.

I'm not sure but I think the default is something like 8k, but since you
don't need to match it exactly, commonly a chunk size of 1024 bytes is used.
The best performace will be when your chunk size <= send buffer size.

A 10MB byte buffer will never be send at once, so creating one large array
is a memory waste.

HTH
greetings

C) Another suggest?

Thanks a lot

Nov 15 '05 #6
AA
Thanks to everyone of you!
"AA" <aa@personal.net.py> escribió en el mensaje
news:ew**************@TK2MSFTNGP11.phx.gbl...
I am writing a socket class that implements the System.Net and
System.Net.Sockets namespaces.

My Question is:

If I need to send a large amount of data through a socket connection (for
example 10MB) which option is better?
A) put all 10MB together in 1 Byte Array and pass it to the Send function

B) create small arrays with less data and send each one by one (which could be the better size if you think that this option is the correct)

C) Another suggest?

Thanks a lot

Nov 15 '05 #7

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

Similar topics

2
3268
by: Gonçalo Rodrigues | last post by:
Hi, My setup is the following: I have socket s from which I want to read and write. So I made the following set up: There is a thread whose only job is to read. Any data read (from recv call)...
1
3378
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
2
15302
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
0
4649
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
6
6438
by: roblugt | last post by:
I have what I imagine is a well-known .Net networking problem, but even though I've Googled for some time I've not yet come across a thread where this has been fully explained... There is a...
4
3591
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
6
2832
by: Sean | last post by:
Hi Everyone, My apologies for a somewhat dump question but I am really stuck. I have been working on this code for two days straight I am dont know what is wrong with it. when I run the code, All...
6
15551
by: billiejoex | last post by:
Hi there. I'm setting up test suite for a project of mine. situations, if the socket is closed on the other end or not. I noticed that I can "detect" such state if a call to socket.read() returns...
1
1815
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear Sir/Mam, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket...
2
2078
by: Ali Hamad | last post by:
Hello All : A socket question from a networking newbie. I need to create a server that: 1) receive a message from client. 2) check that message and response to it. 3) the client get the...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7512
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
5671
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,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.