Re: Asynchronous TCP server -- Misc. questions

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Mochuelo (hola_at_que.tal)
Date: 03/17/05


Date: Thu, 17 Mar 2005 12:14:06 +0100

On Thu, 17 Mar 2005 06:43:30 +0200, "Sean Hederman"
<usemy@blogentry.com> wrote:

>"Mochuelo" <hola@que.tal> wrote in message
>news:ifoh31lcr3irab6kjr5rce7t4nikmqj97m@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.



Relevant Pages

  • Re: Asynchronous TCP server -- Misc. questions
    ... > I'm working with an asynchronous TCP server. ... > server executes the EndAccept method, it is accepting the connection. ... the socket is only available from EndAccept. ... > to execute the specified callback method and blocks on EndAccept until ...
    (microsoft.public.dotnet.languages.csharp)
  • Asynchronous TCP server -- Misc. questions
    ... I'm working with an asynchronous TCP server. ... it is accepting the connection. ... which I could want to reject a connection request, ... to execute the specified callback method and blocks on EndAccept until ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Check connection to db
    ... The usual way would be to execute a dummy query against the server. ... If the connection is lost ... during package execution then the associated task will fail and you can set ...
    (microsoft.public.sqlserver.dts)
  • [ts] system error 31
    ... execute a. ... How much approx 35 or 36 users are connected the server leave ... to have access the internet and lose the connection with the lan. ...
    (microsoft.public.windows.server.general)
  • Re: Outgoing POP3 email missing/lost/not received
    ... Funny thing is that I have had this ISP for 8 years and it has always been ... It looks like when you last ran CEICW, you set the ISP's mail server to: ... Internet Connection Wizard. ... After the wizard completes, the following network connection ...
    (microsoft.public.windows.server.sbs)