Skip to content
Wei-Lun edited this page Nov 27, 2020 · 1 revision
void Sender::SendPacket_2 ()
{
    std::ostringstream      msg;
    msg << "Hello!" << '\0';

    Ptr<Packet>     packet = Create<Packet> ((uint8_t*) msg.str().c_str(), msg.str().length());
    m_socket->Send (packet);
}

static void recvCallback(Ptr<Socket> sock)
{
    Ptr<Packet>     packet = sock->Recv();
    cout << "size:" << packet->GetSize() << endl;

    uint8_t     *buffer = new uint8_t[packet->GetSize()];
    packet->CopyData(buffer, packet->GetSize());
    std::string     str = std::string((char*)buffer);
    std::cout << str << std::endl;
}
Clone this wiki locally