473,386 Members | 1,830 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,386 software developers and data experts.

Asynchronous TCP server -- Misc. questions

Hi,

I'm working with an asynchronous TCP server. I have a few questions
that may seem silly, but I can't get to understand all this.

Let's say that BeginAccept will cause the AcceptCallback method being
executed, and that BeginReceive will cause the ReadCallback method
being execute. I have played a little bit with them, it looks like the
AcceptCallback method gets executed right when a (local or remote)
client requests to connect to this server. I believe that when the
server executes the EndAccept method, it is accepting the connection.
My first silly question is: Why would the server want to reject a
specific connection request, if the Listen method has already
specified in advance the maximum number of simultaneous connections I
want to allow? Could anyone give me an example of a criterium under
which I could want to reject a connection request, assuming the max
number of connections has NOT been reached yet?

Can I know the IP of the client, before accepting the connection
request?

Another question is: The help for BeginAccept says, among other
things:

"Your callback method should implement the EndAccept method. When
your application calls BeginAccept, the system uses a separate thread
to execute the specified callback method and blocks on EndAccept until
a pending connection is retrieved."

I don't understand why it says "blocks". ReadCallback is executed
right at the beginning of every chunk received, or at the end? If it
is executed at the beginning, I could understand the "block". It would
block until the end of the chunk is reached, when all the chunk data
is finally present in the receive buffer. If ReadCallback is executed
at the end of every chunk received, I don't understand the word
"block". Could someone help me understand this?

Thank you very much.

Nov 16 '05 #1
3 1895
I forgot another question.

Each time that the client closes the connection, my ReadCallback gets
executed, but EndReceive returns 0 bytes.

If ReadCallback gets executed, and EndReceive returns 0 bytes, can I
always conclude that the client has closed the connection?

In other words, can I reliably use this symptom to detect (from the
server point of view) that the connnection with a client has been
lost?

Thanks.
Nov 16 '05 #2
"Mochuelo" <ho**@que.tal> wrote in message
news:if********************************@4ax.com...
Hi,

I'm working with an asynchronous TCP server. I have a few questions
that may seem silly, but I can't get to understand all this.

Let's say that BeginAccept will cause the AcceptCallback method being
executed, and that BeginReceive will cause the ReadCallback method
being execute. I have played a little bit with them, it looks like the
AcceptCallback method gets executed right when a (local or remote)
client requests to connect to this server. I believe that when the
server executes the EndAccept method, it is accepting the connection.
Sort of, it's completing the Begin...End started by BeginAccept.
My first silly question is: Why would the server want to reject a
specific connection request, if the Listen method has already
specified in advance the maximum number of simultaneous connections I
want to allow? Could anyone give me an example of a criterium under
which I could want to reject a connection request, assuming the max
number of connections has NOT been reached yet?
You might want to reject connections based on all sorts of criteria, eg.
server load.
Can I know the IP of the client, before accepting the connection
request?
No, the socket is only available from EndAccept.
Another question is: The help for BeginAccept says, among other
things:

"Your callback method should implement the EndAccept method. When
your application calls BeginAccept, the system uses a separate thread
to execute the specified callback method and blocks on EndAccept until
a pending connection is retrieved."

I don't understand why it says "blocks". ReadCallback is executed
right at the beginning of every chunk received, or at the end? If it
is executed at the beginning, I could understand the "block". It would
block until the end of the chunk is reached, when all the chunk data
is finally present in the receive buffer. If ReadCallback is executed
at the end of every chunk received, I don't understand the word
"block". Could someone help me understand this?
"blocks on EndAccept", not ReadCallback. If you don't specify a ReadCallback
(i.e. leave it null), then your code would have to call EndAccept manually.
Once EndAccept is called, assuming it's not finished, your thread will block
until such time as it is.

Thank you very much.

Nov 16 '05 #3
On Thu, 17 Mar 2005 06:43:30 +0200, "Sean Hederman"
<us***@blogentry.com> wrote:
"Mochuelo" <ho**@que.tal> wrote in message
news:if********************************@4ax.com.. .
Hi,

I'm working with an asynchronous TCP server. I have a few questions
that may seem silly, but I can't get to understand all this.

Let's say that BeginAccept will cause the AcceptCallback method being
executed, and that BeginReceive will cause the ReadCallback method
being execute. I have played a little bit with them, it looks like the
AcceptCallback method gets executed right when a (local or remote)
client requests to connect to this server. I believe that when the
server executes the EndAccept method, it is accepting the connection.
Sort of, it's completing the Begin...End started by BeginAccept.


Yes. But, in that sentence, I was thinking from the client point of
view. The client doesn't see its connection request as being accepted
until the server executes exactly which instruction? I believe it is
EndAccept.
My first silly question is: Why would the server want to reject a
specific connection request, if the Listen method has already
specified in advance the maximum number of simultaneous connections I
want to allow? Could anyone give me an example of a criterium under
which I could want to reject a connection request, assuming the max
number of connections has NOT been reached yet?


You might want to reject connections based on all sorts of criteria, eg.
server load.


Ok, that could be a criterium.

The way to reject a connection is by not calling EndAccept, or by
calling it, and then closing the connection?
Can I know the IP of the client, before accepting the connection
request?


No, the socket is only available from EndAccept.


So, the only way to keep away from certain "banned" client IPs would
be to first accept, and then close the connection, I guess.
Another question is: The help for BeginAccept says, among other
things:

"Your callback method should implement the EndAccept method. When
your application calls BeginAccept, the system uses a separate thread
to execute the specified callback method and blocks on EndAccept until
a pending connection is retrieved."

I don't understand why it says "blocks". ReadCallback is executed
right at the beginning of every chunk received, or at the end? If it
is executed at the beginning, I could understand the "block". It would
block until the end of the chunk is reached, when all the chunk data
is finally present in the receive buffer. If ReadCallback is executed
at the end of every chunk received, I don't understand the word
"block". Could someone help me understand this?


"blocks on EndAccept", not ReadCallback. If you don't specify a ReadCallback
(i.e. leave it null), then your code would have to call EndAccept manually.
Once EndAccept is called, assuming it's not finished, your thread will block
until such time as it is.


Understood. That makes sense.

Again, thanks.
Nov 16 '05 #4

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

Similar topics

3
by: Corne Oosthuizen | last post by:
I'm writing a Telnet Server application using Asynchronous sockets. I spawn a listener thread to handel incomming connections and create a separate client socket for each new connection. I...
4
by: taskswap | last post by:
I have a legacy application written in C that I'm trying to convert to C#. It processes a very large amount of data from many clients (actually, upstream servers - this is a mux) simultaneously. ...
1
by: dba123 | last post by:
I need to perform Asynchronous Inserts using DAAB. So far I have a method which does an insert but how can I do this Asyncronously so that it does not affect the load on our public production...
8
by: Simon Gorski | last post by:
I have a large problem, and I believe there is not yet a way to solve this using IIS and ASP.NET. I hope someone has a solution which we couldn't find. The current situation When a user logs...
0
by: Ken T. | last post by:
I have questions regarding what happens on the web server side during an asynchronous web method call when the client aborts its request via .Abort() call. Background: My client app...
0
by: Bishoy George | last post by:
Hi, I have a asp.net 2.0 web application. I want to implement the asynchronous model through http handler in web.config ...
4
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...
7
by: jtbjurstrom | last post by:
Bear with me because we are new to WCF and have been going through documentation and samples trying to absorb as much as possible in a short amount of time. Any suggestions would be much...
4
by: Morgan Cheng | last post by:
Since ASP.NET 2.0, asynchronous web service client can be implemented with event-based pattern, instead of original BeginXXX/EndXXX pattern. However, I didn't find any material about event-based...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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,...
0
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...

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.