Sockets

D

Dan

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
 
M

Mike Meyer

Dan said:
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.)

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.
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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top