0
我在Omnet ++中制作了两个不同的TCP应用程序,一个是TCPBasicClientApp
,另一个是TCPGenericServerApp
。 TCP客户端应用程序通过TCP协议成功发送GenericAppMsg
。一旦在服务器端收到消息(使用特定的replyLength
),它将通过SendBack()
方法(在inet示例应用程序中也提到)将其发送回客户端。如何通过omnet ++中的TCPBasicClientApp接收消息?
我的问题是,如何在客户端接收此消息?
这里是omnet.ini文件的代码,这种转移,
客户端,
**.host[0].numTcpApps = 1
**.host[0].tcpApp[0].typename = "ReputationAlgorithmApplication"
**.host[0].tcpApp[0].localAddress = ""
**.host[0].tcpApp[0].localPort = -1
**.host[0].tcpApp[0].connectAddress = "host[3]"
**.host[0].tcpApp[0].connectPort = 2000
**.host[0].tcpApp[0].dataTransferMode = "object"
服务器端,
**.host[3].numTcpApps = 1
**.host[3].tcpApp[*].typename = "ReputationServerApplication"
**.host[3].tcpApp[*].localAddress = "host[3]"
**.host[3].tcpApp[*].localPort = 2000
这里是服务器上的sendBack方法边,
void ReputationServerApplication::sendBack(cMessage *msg) {
cPacket *packet = dynamic_cast<cPacket *>(msg);
if (packet) {
msgsSent++;
bytesSent += packet->getByteLength();
emit(sentPkSignal, packet);
EV_INFO << "sending \"" << packet->getName() << "\" to TCP, "
<< packet->getByteLength() << " bytes\n";
} else {
EV_INFO << "sending \"" << msg->getName() << "\" to TCP\n";
}
DummyMessageForReputation *msgDum =
dynamic_cast<DummyMessageForReputation *>(msg);
std::cout << "\n Tested: Message with the string "
<< msgDum->getMessageString() << " is sending back to "
<< msgDum->getNodeName();
send(msgDum, "tcpOut");
}
任何帮助,将不胜感激。
是的,这就是我所做的,但这里的问题是它不是从每个节点接收。所以情况就是这样,我有一个由10个节点组成的无线Mesh网络......五个节点,向其他五个节点发送一条消息,接收方应该接收该消息并向发送方回复相同的消息。我可以使用SocketDataArrived()从5中检索3条消息。 由于某些原因,来自两个节点的消息正在从接收方发回,但无法在socketDataArrived()处获取。 –
由于无线环境(如数据包冲突)或接收信噪比不满足无线电要求等原因,很多原因可能导致此问题。您可以使用step模式来查找丢弃了哪个模块,然后逐行调试源代码以准确找到问题所在? –
一行一行地调试代码对我来说几乎是不可能的,因为我在Mac OSX Yosemite上使用了Omnet ++,并且没有可用于此的gdb版本,因此无需调试!如果我可以调试就不会有问题。 我同意你说,很多原因可以导致这个问题,但我不是移动节点的位置,也是每个节点都在其他节点的范围内。我能想到的唯一原因是数据包冲突,可能是我需要为此调整一些无线参数。 谢谢你的帮助。 –