Full duplex socket communication

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Full duplex socket communication

    I'm trying to write client/server networking applications and I've hit
    a bit of a snag. After establishing a connection between client and
    server, data needs to flow asynchronously; that is, I want both the
    client and server to be able to initiate data transfers to the other
    node.

    The select() function immediately comes to mind. If I understand this
    function correctly, it can block until there is data to read or it's
    safe to write. However, most of the time it will be safe to write and
    there will be nothing for it to do. Then I'll need to call select()
    again... and I'll have an ugly busy-waiting loop. Someone please tell
    me if I'm wrong...

    The only other solution I can think of would be to create a
    multi-threaded application, which would create an entirely new set of
    problems I don't want to think about right now. Thanks in advance...
    jahurt@hotmail.com Guest

  2. Similar Questions and Discussions

    1. A (different) duplex printing issue?
      I am having an OS X print issue that seems unique to Acrobat, and I would appreciate some advice. I have a Canon c2880 printer that has a...
    2. How to Print A PDF in Duplex mode
      Hi all, I am new to Acrobat SDK. I am working with .NET and PHP, that deals well with COM Objects. I have a lot of PDF Documents, dinamically...
    3. Automatic Duplex Printing
      Is it possible to embed printing preferences into a PDF? I'm creating an 2 page application that needs to be sent to several other employees at my...
    4. Socket.accept problem via Socket.for_fd($stdin.fileno)
      Hi, I am experiencing a rather infuriating problem with Socket.accept on Windows XP. The problem exists when I try to create a Socket from...
    5. Distinguishing between socket buffer full & socket disconnected
      I am using the IO::Select method can_write() to flow control the writing of a large amount of data to a socket, where the writer may well run ahead...
  3. #2

    Default Re: Full duplex socket communication

    : [email]jahurt@hotmail.com[/email]
    : I'm trying to write client/server networking applications and I've hit
    : a bit of a snag. After establishing a connection between client and
    : server, data needs to flow asynchronously; that is, I want both the
    : client and server to be able to initiate data transfers to the other
    : node.
    :
    : The select() function immediately comes to mind. If I understand this
    : function correctly, it can block until there is data to read or it's
    : safe to write. However, most of the time it will be safe to write and
    : there will be nothing for it to do. Then I'll need to call select()
    : again... and I'll have an ugly busy-waiting loop. Someone please
    : tell me if I'm wrong...

    Do you have anything to write? If not, why are you asking select
    to wake you up when it's safe to write?

    Hence: to avoid the busy loop, simply select only on the various inputs
    if you have nothing to write: if you DO have something to write (and
    need to ensure it's safe, ie, won't block) you could include the write
    socket in the select; but then, you won't be in a busy loop, you'll
    be writing something, then deciding what to wait on the next time.

    Or put it this way: you select only on events for which you will have
    work to do; if the only thing you would do for an event is wait some
    more, you don't ask to wake up for that event, since you're already waiting.


    Wayne Throop [email]throopw@sheol.org[/email] [url]http://sheol.org/throopw[/url]
    Wayne Throop Guest

  4. #3

    Default Re: Full duplex socket communication

    [email]jahurt@hotmail.com[/email] wrote:
    >
    > Tobias Oed <tobias@physics.odu.edu> wrote in message news:<beffnu$4i1k1$1@ID-97389.news.dfncis.de>...
    > > [email]jahurt@hotmail.com[/email] wrote:
    > >
    > > > I'm trying to write client/server networking applications and I've hit
    > > > a bit of a snag. After establishing a connection between client and
    > > > server, data needs to flow asynchronously; that is, I want both the
    > > > client and server to be able to initiate data transfers to the other
    > > > node.
    > > >
    > > > The select() function immediately comes to mind. If I understand this
    > > > function correctly, it can block until there is data to read or it's
    > > > safe to write. However, most of the time it will be safe to write and
    > > > there will be nothing for it to do. Then I'll need to call select()
    > > > again... and I'll have an ugly busy-waiting loop. Someone please tell
    > > > me if I'm wrong...
    > >
    > > If you don't have anything to write don't include that file descriptor in
    > > the set you pass to select.
    > > Tobias
    >
    > Thanks for the reply... perhaps I wasn't clear in my description of
    > the problem.
    > Data needs to flow ansynchronously - that is, data could become
    > available at any time for writing. If select() is waiting for a
    > socket to become available for reading, then I can't write...
    ... but if select() is waiting for something, just how
    does data "become available" for writing? Your program is
    sitting there, stuck in select() and doing nothing at all;
    in particular, it's not generating any data to be written.

    If your program is multi-threaded, with T1 stuck in select()
    while T2 generates data for output, nothing's preventing T2
    from writing its data whenever it pleases.

    Summary: I still don't understand what's troubling you.

    --
    [email]Eric.Sosman@sun.com[/email]
    Eric Sosman Guest

  5. #4

    Default Re: Full duplex socket communication


    <jahurt@hotmail.com> wrote in message
    news:d4ef389d.0307090916.58ecc3bd@posting.google.c om...
    > Thanks for the reply... perhaps I wasn't clear in my description of
    > the problem.
    Definitely.
    > Data needs to flow ansynchronously - that is, data could become
    > available at any time for writing.
    How would data become available for writing exactly?
    > If select() is waiting for a
    > socket to become available for reading, then I can't write...
    Yes, but if 'select' is waiting for a socket to become available for
    reading, you can't do anything else at all. So where would this data that
    became available for writing become available *from*?

    I'm presuming we're not talking about multithreading. If you are, then
    the thread that generates the data that needs to be written can either write
    it itself or force the thread that's in 'select' to stop selecting (say by
    sending a byte on a pipe it's also selecting on).

    DS


    David Schwartz Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139