473,385 Members | 1,907 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.

Socket

I have an asynchronous Server Socket to push data to client (Socket.BeginSend) 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.BeginSend(myData, ...
..
Loo

Client
Do While Tru
..
bytesReceived = m_Socket.Receive(byteBuffer
..
Loo

Nov 16 '05 #1
4 2717
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*******@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
I have an asynchronous Server Socket to push data to client (Socket.BeginSend) 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.BeginSend(myData, ...)
...
Loop

Client:
Do While True
...
bytesReceived = m_Socket.Receive(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*******@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.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*******@discussions.microsoft.com> wrote in message
news:B8**********************************@microsof t.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.BeginSend) 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 = SocketOptionName.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
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...
4
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...
6
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: ...
4
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...
9
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...
2
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...
0
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...
3
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...
5
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...
4
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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
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...
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,...

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.