PC Review


Reply
Thread Tools Rate Thread

Asynchronous TCP server -- Misc. questions

 
 
Mochuelo
Guest
Posts: n/a
 
      17th Mar 2005
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.

 
Reply With Quote
 
 
 
 
Mochuelo
Guest
Posts: n/a
 
      17th Mar 2005
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.
 
Reply With Quote
 
Sean Hederman
Guest
Posts: n/a
 
      17th Mar 2005
"Mochuelo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Mochuelo
Guest
Posts: n/a
 
      17th Mar 2005
On Thu, 17 Mar 2005 06:43:30 +0200, "Sean Hederman"
<(E-Mail Removed)> wrote:

>"Mochuelo" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> 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.
 
Reply With Quote
 
Sean Hederman
Guest
Posts: n/a
 
      17th Mar 2005
"Mochuelo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Thu, 17 Mar 2005 06:43:30 +0200, "Sean Hederman"
> <(E-Mail Removed)> wrote:
>
>>"Mochuelo" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> Hi,

[Snip]
> The way to reject a connection is by not calling EndAccept, or by
> calling it, and then closing the connection?


I'd prefer to call EndAccept and then close the connection. My worry would
be that keeping the listener open would result in blocking the socket to
other connections (since nothing will be waiting for them). In addition I'm
pretty certain that you can't call BeginReceive followed by BeginReceive,
you have to call EndReceive between them.

>>> 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.


Yep.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Misc Questions about Tables - Please help Fill-in Form General Questions Microsoft Word Document Management 1 29th Apr 2008 03:20 PM
Need help with misc FP 2000 questions ... brooksr Microsoft Frontpage 3 13th Mar 2007 02:11 PM
misc short questions =?Utf-8?B?Q2F0IFdpbnNsb3c=?= Microsoft Access Database Table Design 2 20th Sep 2006 10:27 PM
Misc. Questions--help Me, Please!!!:( Shanep Windows XP Help 0 15th Feb 2006 10:18 PM
misc questions instauratio Microsoft Outlook Discussion 3 2nd Jul 2004 12:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 PM.