473,729 Members | 2,301 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

network read question

Hi,

When does the socket (server) know when to stop reading.

e.g.

if i have a buffer = 25K

and do networkStream.w rite twice.. what will the server read? 25k or
50K?

And should i send a message length for every message i send? and make
the server read specified number of bytes?
networkStream.W rite(buffer, 0, buffer.Length);
networkStream.W rite(buffer, 0, buffer.Length);
*************** *******Server Code *************** *************** *****
Socket newsock = new
Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);

newsock.Bind(ip ep);
newsock.Listen( 10);
Socket client = newsock.Accept( );
data = new byte[64000];

recv = client.Receive( data);

*************** *************** *************** *



Apr 9 '08 #1
4 1644
On Wed, 09 Apr 2008 15:03:38 -0700, parez <ps*****@gmail. comwrote:
When does the socket (server) know when to stop reading.

e.g.

if i have a buffer = 25K

and do networkStream.w rite twice.. what will the server read? 25k or
50K?
If you write 50K, the server will eventually read 50K. However, there is
no way to predict in advance how the server will read that 50K. It could
read a single byte 50 thousand times, it could read 5 bytes ten thousand
times, it could read 50K once, it could read 10K, 10K, 25K, then 5K, it
could...

Any possible permutation is possible.
And should i send a message length for every message i send? and make
the server read specified number of bytes?
With TCP (which is what NetworkStream implies), you _must_ provide some
mechanism to allow the recipient to know how long the transmission is.

In the simplest case, the transmission is "complete" when the connection
is closed. For some protocols, that's sufficient. For higher-performance
protocols, where you want to leave the connection open between your
logical messages, you need to incorporate some means of delimiting
messages. Preceding each logical message with a byte count is indeed a
legitimate and common way to accomplish that.

Pete
Apr 9 '08 #2
On Apr 9, 6:20 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
wrote:
On Wed, 09 Apr 2008 15:03:38 -0700, parez <psaw...@gmail. comwrote:
When does the socket (server) know when to stop reading.
e.g.
if i have a buffer = 25K
and do networkStream.w rite twice.. what will the server read? 25k or
50K?

If you write 50K, the server will eventually read 50K. However, there is
no way to predict in advance how the server will read that 50K. It could
read a single byte 50 thousand times, it could read 5 bytes ten thousand
times, it could read 50K once, it could read 10K, 10K, 25K, then 5K, it
could...

Any possible permutation is possible.
And should i send a message length for every message i send? and make
the server read specified number of bytes?

With TCP (which is what NetworkStream implies), you _must_ provide some
mechanism to allow the recipient to know how long the transmission is.

In the simplest case, the transmission is "complete" when the connection
is closed. For some protocols, that's sufficient. For higher-performance
protocols, where you want to leave the connection open between your
logical messages, you need to incorporate some means of delimiting
messages. Preceding each logical message with a byte count is indeed a
legitimate and common way to accomplish that.

Pete
Thanks..
I have a situation where i sending a approx 50k message. the server
is reading it into a 128 k buffer. but it only 2k (most of the times)
and the number varies.. the server program is written so that it
quits reading after the first read
(max size of the message is apprx 65K). So i will have to send the
first x bytes as message length?

Coming back to the original question, there is no way of certainly
knowing how many bytes will the server read in one go...
Apr 9 '08 #3
On Wed, 09 Apr 2008 15:40:34 -0700, parez <ps*****@gmail. comwrote:
I have a situation where i sending a approx 50k message. the server
is reading it into a 128 k buffer. but it only 2k (most of the times)
and the number varies..
Sounds about right. Over the Internet, the maximum transmission unit
(MTU) is just under 2K. So it's not uncommon to receive data in chunks of
that size (i.e. just under 2K). Different segments along the route may
have different MTUs and other factors can also cause the actual data
delivered to arrive in varying lengths. But it's not unusual to see sizes
in that ballpark.
the server program is written so that it
quits reading after the first read
Well, that's a bug.
(max size of the message is apprx 65K). So i will have to send the
first x bytes as message length?
You don't have to. But you do have to do _something_ like that. Sending
the message length first is a common solution, but it's not mandatory.
The only thing that is mandatory is that the recipient can reliably
delimit the incoming data.
Coming back to the original question, there is no way of certainly
knowing how many bytes will the server read in one go...
No. There's not.

Pete
Apr 9 '08 #4
I have a situation where i sending *a approx 50k message. the server
is reading it into a 128 k buffer. *but it only 2k (most of the times)
and the number varies.. the server program is written *so that it
quits reading after the first read
Do you have the code of the server?
Remember that even as you say read X bytes you will get only the
bytes that were read already. The server usually works in a loop.
(max size of the message *is apprx 65K). So i will have to send the
first x bytes as message length?
Does the server support that?
If not the length will become part of the data.
Coming back to the original *question, *there is no way of certainly
knowing *how many bytes will the server read in one go...
Nop
Apr 10 '08 #5

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

Similar topics

36
16405
by: Thomas | last post by:
after spending countless hours trying, i give up and hope to get some help in here. on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm trying to read a file from an UNC path with a FSO: Set myFile = Server.CreateObject("Scripting.FileSystemObject").GetFile("\\server2\myshare\myfile.txt") this fails with an Permission Denied. here's the deal:
3
1546
by: Alienz | last post by:
Hey guys heres my network question: 1- when I selet Tools-startup and limit the access to access, it applies to all of the users on the network who are accessing the database through a network folder. How can I let the startup feature be unique for whoever has it setup. Would it have to do with creating a linked replica that each user uses (tools menu-create replica). I havent looked at the password issues yet so this is my main...
2
5136
by: Leonardo D'Ippolito | last post by:
Hi! I have two .NET win apps that need to communicate on a TCP/IP network. 'App A' must ask 'app B' if it's allowed to do some task, and 'app B' must authorize or prohibit it. How can I do this kind of communication in a secure way (protected from sniffing)? It would be a very simple protocol. Question, and two possible answers 'yes' or 'no'.
0
1170
by: cig | last post by:
Using VS.Net 2K3 Pro. My development environment is set up with project & source files on a network drive and until a recent server hardware failure followed by a restore/rebuild this worked very well. I now find that the code blows up with the FileIoPermission error when I try to run either the project in debug/release mode from the IDE or the built exe from the network drive. The first time I tried to run a project setup like this...
1
6570
by: brian.oneil2 | last post by:
Is there a way to install this onto a network file share and allow a team to access it? I would say share a CD from a networked CD drive, but there are multiple CD's that would have to be inserted. TIA, Brian
7
3150
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the same time. My scenario is a small server application that listens on a particular TCP port. I am sending streams of data to it via a client app. Inside
5
3109
by: Dave Kolb | last post by:
Is there any other solution for an ASPNET application to access network resources other than running as SYSTEM, using delegation (a nightmare to get to work) or the COM+ solution? I cannot seem to impersonate a user and obtain network credentials using the DuplicateTokenEx call with appropriate parameters even though the call seems to not fail. I check my identity has changed but can only still do local commands. I would consider...
11
3069
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read files on Windows domain network shared drives and also on shared via Samba Unix drives, which is equivalent to writing/reading to the workgroup computer. Please point, if possible, to detailed step by step description of what needs to be done. Thank...
8
1989
by: Frank Millman | last post by:
Hi all This is not strictly a Python question, but as the system to which relates is written in Python, hopefully it is not too off-topic. I have an accounting/business application, written in client/server mode. The server makes a connection to a database, and then runs a continuous loop waiting for client connections, establishes a session with the client, and responds to messages received from the client until the client closes the...
1
20635
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
0
8921
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4528
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
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 we have to send another system
3
2165
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.