How to listen on two sockets in the same application



Hello,

I'm writing a server program that will listen on both IPv4 and IPv6.
Thus, I'm creating two sockets for the two different address families
and will have to listen on both. However, in my past experience on
writing code using listen, the listen call blocks the application until
a connection request is made by some outside entity. Since I've got to
listen on two sockets, how do I accomplish this?

I'm thinking that something like this won't work:

listen( sock1, 5 ); // app is blocked here until connect from client
listen( sock2, 5 );

Is this going to be accomplished by somehow using fcntl to configure
the sockets for non-blocking and then using select on the sockets?

Oh, I don't know if this will add much complexity to things, but I'm
writing all this in C++ and am hoping to wrap the handling of
communication over the two respective address families within
classes/objects. Please bear that in mind with any answers.

Thanks everyone,

Andy

.



Relevant Pages

  • Re: Sockets and Forwarding On Java
    ... writing non-text characters from/to network sockets? ... sockets, and what came through one had to be copied over to the other, I ... stream while another one is writing to its input stream -- or with ... Linux when I tried that. ...
    (comp.lang.java.help)
  • Re: How to listen on two sockets in the same application
    ... I'm writing a server program that will listen on both IPv4 and IPv6. ... I'm creating two sockets for the two different address families ...
    (comp.unix.programmer)
  • Re: Update service without restarting it
    ... If it was me I would talk to the service using sockets, instead of writing ... i am writing some command into the file and my service is ... without restarting it? ...
    (microsoft.public.vc.mfc)
  • Re: How to listen on two sockets in the same application
    ... I'm writing a server program that will listen on both IPv4 and IPv6. ... I'm creating two sockets for the two different address families ... writing code using listen, the listen call blocks the application until ... how do I accomplish this? ...
    (comp.unix.programmer)
  • Re: Advice on Writing my own socket code vs using MFC built in classes
    ... "justmehere" wrote in message ... of writing the sockets programming part of it. ... I have read somewhere that using MFC may be more difficult. ... CAsyncSocket is reliable and offers a few conveniences over writing your own socket code. ...
    (microsoft.public.vc.mfc)

Quantcast