473,666 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket

I have an asynchronous Server Socket to push data to client (Socket.BeginSe nd) when data is available, Meanwhile, the client socket use Synchronous Client Socket to receive the data. I have two questions on this

1. When client socket does not receive data as fast as server, does server socket queues all the data, or just waits? If it queues, this may kill server

2. I declare socket receive buffer big enough, when I call Socket.Receive method, Does the client always receive one pushed data, or it may receive part of one pushed data, or it may receive one pushed data plus part of next pushed data? I tested it, it looks like one pushed data, but I am not sure enough

Thank

Server

Do While Tru
..
myData = GetData() '
m_Socket.BeginS end(myData, ...
..
Loo

Client
Do While Tru
..
bytesReceived = m_Socket.Receiv e(byteBuffer
..
Loo

Nov 16 '05 #1
4 2739
Are you using UDP or TCP sockets? If you are using TCP sockets, then all of
the data will be received by the client, since TCP tries to prevent data
loss. If you're using a UDP socket, then you should be able to flush data
out of the socket rapidly on the server, and the client will be able to pick
up whatever it can, and drop the rest of the packets it can't.

In theory your receiving socket could get data from more than one write
attempt on the server. The data is all pushed together into one buffer, so
the reason you appear to be getting a single write's data in your read
attempt is that the processes are lining up well. This may not always be
the case.

Ryan Gregg
"Qingdong Z." <an*******@disc ussions.microso ft.com> wrote in message
news:A2******** *************** ***********@mic rosoft.com...
I have an asynchronous Server Socket to push data to client (Socket.BeginSe nd) when data is available, Meanwhile, the client socket use
Synchronous Client Socket to receive the data. I have two questions on this:
1. When client socket does not receive data as fast as server, does server socket queues all the data, or just waits? If it queues, this may kill
server.
2. I declare socket receive buffer big enough, when I call Socket.Receive method, Does the client always receive one pushed data, or it may receive
part of one pushed data, or it may receive one pushed data plus part of next
pushed data? I tested it, it looks like one pushed data, but I am not sure
enough.
Thanks

Server:

Do While True
...
myData = GetData() 'M
m_Socket.BeginS end(myData, ...)
...
Loop

Client:
Do While True
...
bytesReceived = m_Socket.Receiv e(byteBuffer)
...
Loop

Nov 16 '05 #2
Ryan

Thank for your comments. I am using TCP sockets. If the receiving socket get more than one write, it would be the nightmare to me. But I tested it again in my case. When Server gets data, it writes the same data three times to socket (Original is one time). The average data is about 10K. I set client receive buffer about 60K, but the client socket still get one write everytime. By the way, I tested socket server and client on the same computer.
Nov 16 '05 #3
If they're always going to be running on the same computer, that should work
then. You might want to test it on different systems to make sure you get
the same behavior, since locally it's using the loopback adapter which might
have different properties than a real network adapter.

If I get a chance I'll write up a test program and see if I can confirm the
behavior I was discussing.

Ryan Gregg

"Qingdong Z." <an*******@disc ussions.microso ft.com> wrote in message
news:8E******** *************** ***********@mic rosoft.com...
Ryan,

Thank for your comments. I am using TCP sockets. If the receiving socket

get more than one write, it would be the nightmare to me. But I tested it
again in my case. When Server gets data, it writes the same data three times
to socket (Original is one time). The average data is about 10K. I set
client receive buffer about 60K, but the client socket still get one write
everytime. By the way, I tested socket server and client on the same
computer.
Nov 16 '05 #4
If you are using the BeginSend operation, then you won't have to worry about
the server blocking on the call. Since BeginSend is an async method, it
will never block, however, the operation may not complete in a timely
manner. You may want to listen for the call back event to ensure that your
transmission was sent before sending the next packet of data.

As far as #2, I'm not sure. I haven't tried using the NoDelay socket option
to see what happens.

Ryan Gregg

"Qingdong Z." <an*******@disc ussions.microso ft.com> wrote in message
news:B8******** *************** ***********@mic rosoft.com...
Ryan,

I found your comments are correct. I debug/break socket client in the same computer, and socket client received more than one write. I think when the
network and client side are fast enough, client can get each single write
from server.
I have two questions that need your comments:

1. When client and network are slow, will server be blocked (Socket.BeginSe nd) when network buffer is full? Or server will continue send
until run out of resource? My application is video related, it consumes too
much resource.
2. Can SetSocketOption = SocketOptionNam e.NoDelay solves the problem?

Thanks.

Nov 16 '05 #5

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

Similar topics

8
9276
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added it, and my code now works simply and as expected. def close(self):
4
8721
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code ----------------------------- namespace Sockets { #region Class - SocketClient
6
4107
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: Connect Receive response Send Connect ACK
4
18111
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call shutdown and close asynchronously if possible.
9
3597
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so that its buffer is bigger than this. I did this expecting the data to be read in one pass.
2
6871
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
0
4670
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 number of different types of data coming in. I have a databuffer for each type of data coming in.
3
4292
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the receiver is running within Process1. If I move the receiver into Process2 then its fast. Please can someone explain.
5
12777
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for more incoming connections and does the BeginAccpet() again. It does an infinite loop this way. My question is: What is the best way to stop this? I thought about putting a boolean in there, but then what if it's still waiting for an incoming...
4
16103
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open the socket again, the bind fails because the port is still in use. When I execute the code in "debug" mode, the problem never occurs. When I execute the same code in release mode, the problem appears about 20% of the time. Here's the code:
0
8444
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
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
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
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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
5664
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
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
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.