Sockets

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

    Sockets



    I have a problem and I don't quite know how to implement the solution.

    I'll have a server application that will listen on a tcp port and make
    many similtaneous connections to remote clients. From time to time,
    I'll need to write a small amount of data on one of those sockets. A
    notification to write to one of the sockets will come from another
    program/process.

    I think that the best way to send the notification to this server
    application is via a udp message. Alternatively, I could use tcp, but
    I don't think I'll need the extra complexity for what I want to do.
    (Other suggestions welcome.)

    The server application will multiplex the connections using 'select',
    so much of the time it will be blocked on 'select'.

    My problem is how to also listen on a udp port while the process is
    blocked by 'select'. Should I run a separate thread? And if so can I
    share the socket connection across the two threads? (Thread 1 will be
    accepting client connections, thread 2 will we writing data to it.)
    Or should I simply let 'select' time out after some period?

    I'm a bit lost as to how to do this, I hope someone can put me on the
    right track. Any solution that I use should be applicable on Linux
    and Windows platforms.

    Thanks

    Dan
  • Mike Meyer

    #2
    Re: Sockets

    Dan <dan@dontspamme causeidontlikit .com> writes:
    [color=blue]
    > I think that the best way to send the notification to this server
    > application is via a udp message. Alternatively, I could use tcp, but
    > I don't think I'll need the extra complexity for what I want to do.
    > (Other suggestions welcome.)[/color]

    upd isn't reliable. If you need reliability, you'll have to build it
    yourself. In which case, it might be easier to use tcp.
    [color=blue]
    > My problem is how to also listen on a udp port while the process is
    > blocked by 'select'. Should I run a separate thread? And if so can I
    > share the socket connection across the two threads? (Thread 1 will be
    > accepting client connections, thread 2 will we writing data to it.)
    > Or should I simply let 'select' time out after some period?[/color]

    A udp port is just another socket - meaning another file
    descriptor. Unix being what it is, I'd expect that select would handle
    sockets opened for udp just fine. Have you tried that and had it fail?

    <mike
    --
    Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

    Comment

    Working...