Socket

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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. said:
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.
 
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.
 
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. said:
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.
 
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. said:
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.
 
Back
Top