我的消息类看起来像这样..
message Custom {
string src;
float xPos;
float yPos;
bool target;
}
我已经扩展了 UdpBasicApp 来发送此自定义消息类..
在sendpacket()中..我有这样的代码..
const char* sourceModuleName = getParentModule()->getFullName();
// Get the current position of the node
IMobility* mobilityModule = check_and_cast<IMobility*>(getParentModule()->getSubmodule("mobility"));
Coord currentPosition = mobilityModule->getCurrentPosition();
EV_INFO << " (Original: " << currentPosition.x << ")" << endl;
EV_INFO << "(Original: " << currentPosition.y << ")" << endl;
std::ostringstream str;
std::string packetNameStr = "CustomPacket"; // Set an appropriate name for the packet
const char* packetName = packetNameStr.c_str();
Custom *customPacket = new Custom(packetName);
customPacket->setXPos(currentPosition.x);
customPacket->setYPos(currentPosition.y);
customPacket->setSrc(sourceModuleName);
customPacket->setTarget(false);
cMemCommBuffer buffer;
customPacket->parsimPack(&buffer);
inet::Packet *inetPacket = new inet::Packet("CustomPacket");
inetPacket->insertAtBack(customPacket);
socket.sendTo(inetPacket, destAddr, destPort);
但是我遇到了错误...因为socket.sendTo()只发送数据包的数据,而且我有自定义数据包,我也不能做这件事。inetPacket->insertAtBack(customPacket);..请指导情况...提前致谢
我可以看看你的源代码吗?我也有同样的问题。