Socket Handle Read Is never read In Ns3

Viewed 13

I stayed many days to find where the error is and I'm stuck.Can anyone help me please.

MY application is a clustering program in NS3 that was written from one else and free to anyone. The program is run and no errors and print messages but always the number of neighbors in every Cluster Head CH is zero, this mean that the hellow messages are not reach every node and every node consider itself as cluster head because it dosn't see any neighbor node!. every node (vehicle) has two sockets one for send data m_socket and one for listening m_socketlistening, the code is:

if (!m_socket)
 {
    //  TypeId::LookupByName ("ns3::UdpSocketFactory
    
    TypeId m_tid = TypeId::LookupByName("ns3::UdpSocketFactory");
    //m_socket = Socket::CreateSocket(GetNode() , TypeId::LookupByName("ns3::UdpSocketFactory"));
    m_socket = Socket::CreateSocket(GetNode(), m_tid);
    // i added the down line

  // InetSocketAddress remote = InetSocketAddress(Ipv4Address::GetBroadcast(),80);

    if (Inet6SocketAddress::IsMatchingType(m_peer)) 
    {
        m_socket->Bind6();
    } 
    else if (InetSocketAddress::IsMatchingType(m_peer)
            || PacketSocketAddress::IsMatchingType(m_peer))
    {
         
        m_socket->Bind();
    }
   

    m_socket->SetAllowBroadcast(true);
    m_socket->ShutdownRecv();
    
     m_socket->SetConnectCallback(
     MakeCallback(&V2vControlClient::ConnectionSucceeded, this),
     MakeCallback(&V2vControlClient::ConnectionFailed, this));
     //m_socket->Connect(Ipv4Address::GetBroadcast());
     m_socket->Connect(m_peer);

}

now this is a part pf the listening socket creation

if (!m_socketListening)
{

NS_LOG_UNCOND("\n ...creating socket muhsen...");
    m_socketListening = Socket::CreateSocket(GetNode(), m_tidListening);
    m_socketListening->Bind(m_peerListening);
    m_socketListening->Listen();
    m_socketListening->ShutdownSend();
    if (addressUtils::IsMulticast(m_peerListening)) 
    {
        Ptr<UdpSocket> udpSocket = DynamicCast<UdpSocket>(m_socketListening);
        if (udpSocket)
        {   
            // equivalent to setsockopt (MCAST_JOIN_GROUP)
            udpSocket->MulticastJoinGroup(0, m_peerListening);
        } 
      else 
        {
            NS_FATAL_ERROR("Error: joining multicast on a non-UDP socket");
        }
    }
}



m_socketListening->SetRecvCallback(MakeCallback(&V2vControlClient::HandleRead, this));
m_socketListening->SetAcceptCallback(
        MakeNullCallback<bool, Ptr<Socket>, const Address &>(),
        MakeCallback(&V2vControlClient::HandleAccept, this));
m_socketListening->SetCloseCallbacks(
        MakeCallback(&V2vControlClient::HandlePeerClose, this),
        MakeCallback(&V2vControlClient::HandlePeerError, this));

   



void  V2vControlClient::HandleRead (Ptr<Socket> socket)
{

NS_LOG_UNCOND("\n this message is never executed..");


NS_LOG_FUNCTION (this << socket);
Ptr<Packet> packet;
Address from;

while ((packet = socket->RecvFrom(from)))
   {
    if (packet->GetSize() == 0) 
    { //EOF
        break;
    }

When i run the application the first statement after the HandleRead Function which is NS_LOG_UNCOND("\n this message is never executed.."); is never printed when run the program, this means that the handle read is never executed. Any help is very appreciate!

0 Answers
Related