Boost logo

Boost Users :

Subject: [Boost-users] Asio : opening two udp::sockets on differentports
From: Étienne Lepercq (etienne.lepercq_at_[hidden])
Date: 2009-11-13 14:03:36


I am not a specialist in TCP/UDP communications, but I am trying to implement
some communications using UDP packets (v6). I can't use anything else than UDP
v6 due to external constraints. I am using boost 1.37. I tried boost 1.40, same
problem (see below)

I have implemented a first architecture, working like :

  - a server listens to UDP packets v6 coming on a port ( let's say 65000).
  - a client connects to that port by sending a UDP packet.
  - the server starts a new thread, which listens for udpv6 packets on another
port
  - the client should deconnect and reconnect to that other port.

Cleitns starts opening the first socket like that :

boost::asio::io_service io_service;
udp::endpoint endpoint;
udp::socket socket(io_service);
udp::resolver::query query(udp::v6(), m_host, m_port);
udp::resolver resolver(io_service);
endpoint = *resolver.resolve(query);
socket.open(udp::v6());

Then a function is called that sends a packet, receive an answer, etc... WORKS !

Then, I would like that socket being closed, and reopened on the same host, but
on a different port. Something like this :

socket.close();
udp::socket socket(io_service);
udp::resolver::query query2(udp::v6(), m_host, NEWPORT);
udp::resolver resolver2(io_service);
endpoint = *resolver2.resolve(query2);
socket.open(udp::v6());

But it fails miserably, throwing exception "Host not found (Authoritative)" on
this second attempt. m_host is the ipv6 loopback address, "::1".

I tried declaring at the same time, a full new set of io_service, endpoint,
socket, query, resolver : the very same thing happens !
That said, there is another thread listening on the NEWPORT for udp v6 packets.
I am developping mainly under linux, using lsof lists exactly the right number
of ports opened (m_port and NEWPORT are opened for udpv6)

So what is incorrect ? I don't really understand the behavior and complexity of
io_service, maybe that's the problem ?
How can I reopen a second socket on another port ? That port being listed by the
system as opened succesfully, I really think the problem lies in that section.

Thank you !


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net