Asynchronous Sockets clarification

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • family.sens@gmail.com

    #1

    Asynchronous Sockets clarification

    i need to know .... if im using Async sockets (using callbacks and
    BeginSend()) calls..... can i do way with spawning Threads ?

    the way my program works

    1. Listen on socket X
    2. when connections come in (multiple connections possib), i process
    the data, send it to another server, get the data and return it via the
    SAME thread that sent the data initially.i was earlier thinking of
    doing this

    Receive-Process-Send To SErver-Get Data-Return to SOcket Where i
    Received It From

    process using a different thread....

    now im confused, because i read somewhere that the Async method spawns
    threads internally....

    Question: HOW do i know which socket has sent the data ?

    TIA!

  • family.sens@gmail.com

    #2
    Re: Asynchronous Sockets clarification

    Oh , and im Using VS 2003 to do all this .. in case THAT makes any diff
    , i havent worked on Whidbey at all so i dunno.

    Comment

    • Markus Stoeger

      #3
      Re: Asynchronous Sockets clarification

      family.sens@gma il.com wrote:[color=blue]
      > Question: HOW do i know which socket has sent the data ?[/color]

      Every socket.BeginXXX method has an "object state" parameter, into which
      you can pass any object (like a socket).

      When a callback gets called it gets an IAsyncResult as parameter. The
      IAsyncResult contains an "object AsyncResult", which is the same thing
      you passed to the BeginXXX method.

      hth,
      Max

      Comment

      • William Stacey [MVP]

        #4
        Re: Asynchronous Sockets clarification

        You could use sync. If you want to use the same thread: Get connection,
        spawn a client thread passing socket. Client thread now blocks on second
        server call and returns. You could also use your own thread pool for client
        workers. If want to use the same thread, there is no advantage in using
        async as the client thread has to block anyway waiting for the server reply
        in order to reply to the client.

        --
        William Stacey [MVP]

        <family.sens@gm ail.com> wrote in message
        news:1140329675 .461942.286450@ g44g2000cwa.goo glegroups.com.. .
        |i need to know .... if im using Async sockets (using callbacks and
        | BeginSend()) calls..... can i do way with spawning Threads ?
        |
        | the way my program works
        |
        | 1. Listen on socket X
        | 2. when connections come in (multiple connections possib), i process
        | the data, send it to another server, get the data and return it via the
        | SAME thread that sent the data initially.i was earlier thinking of
        | doing this
        |
        | Receive-Process-Send To SErver-Get Data-Return to SOcket Where i
        | Received It From
        |
        | process using a different thread....
        |
        | now im confused, because i read somewhere that the Async method spawns
        | threads internally....
        |
        | Question: HOW do i know which socket has sent the data ?
        |
        | TIA!
        |


        Comment

        • Peter Bromberg [C# MVP]

          #5
          RE: Asynchronous Sockets clarification

          All of the BeginXXX / EndXXX method signatures automatically use a Threadpool
          thread in the background.
          Peter

          --
          Co-founder, Eggheadcafe.com developer portal:

          UnBlog:





          "family.sens@gm ail.com" wrote:
          [color=blue]
          > i need to know .... if im using Async sockets (using callbacks and
          > BeginSend()) calls..... can i do way with spawning Threads ?
          >
          > the way my program works
          >
          > 1. Listen on socket X
          > 2. when connections come in (multiple connections possib), i process
          > the data, send it to another server, get the data and return it via the
          > SAME thread that sent the data initially.i was earlier thinking of
          > doing this
          >
          > Receive-Process-Send To SErver-Get Data-Return to SOcket Where i
          > Received It From
          >
          > process using a different thread....
          >
          > now im confused, because i read somewhere that the Async method spawns
          > threads internally....
          >
          > Question: HOW do i know which socket has sent the data ?
          >
          > TIA!
          >
          >[/color]

          Comment

          Working...