How to pool on socket ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • User

    #1

    How to pool on socket ?

    Hi,

    How do I pool my socket to see if there is any message pending?

    I don't want to use timers because they are multithreaded and it break
    the linearity of my messages. (incoming message are numbered and it is
    important to keep the order)

    Can I add a handler to the socket? So it could react by itself when
    there is pending data? Something like that the winsock (in VB6) was doing.

    Thank you.


  • Tom Shelton

    #2
    Re: How to pool on socket ?

    In article <dcaOc.118392$R f.22568@edtnps8 4>, User wrote:[color=blue]
    > Hi,
    >
    > How do I pool my socket to see if there is any message pending?
    >
    > I don't want to use timers because they are multithreaded and it break
    > the linearity of my messages. (incoming message are numbered and it is
    > important to keep the order)
    >
    > Can I add a handler to the socket? So it could react by itself when
    > there is pending data? Something like that the winsock (in VB6) was doing.
    >
    > Thank you.[/color]

    The absolute best way to do this would most likely be to use the asnyc
    methods of the socket class (BeginXXXX). The socket will then fire a
    callback when data is received.

    You could also use the Poll method on the socket to determine if there
    is data. You can also use Socket.Select along with Receive with the
    Peek flag to determine the socket state...

    There are a number of ways that you can accomplish what you're asking,
    but the Asnyc methods are usually the most efficient.
    --
    Tom Shelton [MVP]

    Comment

    • User

      #3
      Re: How to pool on socket ?

      Thank you Tom,

      I have another question. I haven't use this async socket yet, but I'll
      read on it. Right now, I am using a timer control to pool over the
      socket.pending to see if there is new data to process. The timer is
      running all day long.

      Does the async socket, once started, will pool the socket as long as it
      is not stopped? I mean, I start it once and will run as the same way I
      am using the timer control right now?

      Thank you.

      Tom Shelton wrote:[color=blue]
      > In article <dcaOc.118392$R f.22568@edtnps8 4>, User wrote:
      >[color=green]
      >>Hi,
      >>
      >>How do I pool my socket to see if there is any message pending?
      >>
      >>I don't want to use timers because they are multithreaded and it break
      >>the linearity of my messages. (incoming message are numbered and it is
      >>important to keep the order)
      >>
      >>Can I add a handler to the socket? So it could react by itself when
      >>there is pending data? Something like that the winsock (in VB6) was doing.
      >>
      >>Thank you.[/color]
      >
      >
      > The absolute best way to do this would most likely be to use the asnyc
      > methods of the socket class (BeginXXXX). The socket will then fire a
      > callback when data is received.
      >
      > You could also use the Poll method on the socket to determine if there
      > is data. You can also use Socket.Select along with Receive with the
      > Peek flag to determine the socket state...
      >
      > There are a number of ways that you can accomplish what you're asking,
      > but the Asnyc methods are usually the most efficient.[/color]

      Comment

      • Tom Shelton

        #4
        Re: How to pool on socket ?

        On Fri, 30 Jul 2004 12:36:13 GMT, User wrote:
        [color=blue]
        > Thank you Tom,
        >
        > I have another question. I haven't use this async socket yet, but I'll
        > read on it. Right now, I am using a timer control to pool over the
        > socket.pending to see if there is new data to process. The timer is
        > running all day long.
        >
        > Does the async socket, once started, will pool the socket as long as it
        > is not stopped? I mean, I start it once and will run as the same way I
        > am using the timer control right now?
        >
        > Thank you.[/color]

        Basically, once you begin the async operation, it will continue until the
        socket is closed - or the call back is fired. Once it is fired, you need
        to call the async method again... So just for a quick psuedo code example:

        begin serverfunc
        socket.bind
        socket.listen
        while (running)
        manualreseteven t.reset
        socket.beginacc ept
        manualreseteven t.waitone
        wend
        end serverfunc


        begin acceptfunc
        ' get socket object
        client = get_from_async_ object

        ' signal server thread to continue
        manualreseteven t.set

        client.beginrea d
        end acceptfunc

        begin readfunc
        ' do read stuff

        ' send a reply
        client.beginsen d
        end readfunc

        begin sendfunc
        if sent client.beginrea d
        end sendfunc

        etc, etc...

        There are some good articles on msdn (this should get you in the correct
        location):

        http://msdn.microsoft.com/library/de...rverSocket.asp

        There is a little more code involved in using the async methods, but they
        are the most scalable and efficient.

        --
        Tom Shelton [MVP]

        Comment

        • User

          #5
          Re: How to pool on socket ?

          That is very interesting Tom, I red the article on MSDN, I got to use it.

          Thank you very much.



          Tom Shelton wrote:[color=blue]
          > On Fri, 30 Jul 2004 12:36:13 GMT, User wrote:
          >
          >[color=green]
          >>Thank you Tom,
          >>
          >>I have another question. I haven't use this async socket yet, but I'll
          >>read on it. Right now, I am using a timer control to pool over the
          >>socket.pendin g to see if there is new data to process. The timer is
          >>running all day long.
          >>
          >>Does the async socket, once started, will pool the socket as long as it
          >>is not stopped? I mean, I start it once and will run as the same way I
          >>am using the timer control right now?
          >>
          >>Thank you.[/color]
          >
          >
          > Basically, once you begin the async operation, it will continue until the
          > socket is closed - or the call back is fired. Once it is fired, you need
          > to call the async method again... So just for a quick psuedo code example:
          >
          > begin serverfunc
          > socket.bind
          > socket.listen
          > while (running)
          > manualreseteven t.reset
          > socket.beginacc ept
          > manualreseteven t.waitone
          > wend
          > end serverfunc
          >
          >
          > begin acceptfunc
          > ' get socket object
          > client = get_from_async_ object
          >
          > ' signal server thread to continue
          > manualreseteven t.set
          >
          > client.beginrea d
          > end acceptfunc
          >
          > begin readfunc
          > ' do read stuff
          >
          > ' send a reply
          > client.beginsen d
          > end readfunc
          >
          > begin sendfunc
          > if sent client.beginrea d
          > end sendfunc
          >
          > etc, etc...
          >
          > There are some good articles on msdn (this should get you in the correct
          > location):
          >
          > http://msdn.microsoft.com/library/de...rverSocket.asp
          >
          > There is a little more code involved in using the async methods, but they
          > are the most scalable and efficient.
          >[/color]

          Comment

          Working...