如何通过omnet ++中的TCPBasicClientApp接收消息?

时间:2015-09-07 04:53:47

标签: tcp tcpclient omnet++

我在Omnet ++中创建了两个不同的TCP应用程序,一个是TCPBasicClientApp,另一个是TCPGenericServerApp。 TCP客户端应用程序通过TCP协议成功发送GenericAppMsg。一旦在服务器端收到消息(具有特定的replyLength),它就会通过SendBack()方法将其发送回客户端(在inet示例应用程序中也会提到)。

我的问题是,如何在客户端收到此消息?

这是传输的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");
}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可以使用String sql = "select field1 as field1Sample, field2 as field2Sample, field3 as field3Sample from sample where field3=:field3 order by field_id asc"; Query query = sessionFactory.getCurrentSession().createSQLQuery(sql); query.setParameter("field3", 1); query.setResultTransformer(Transformers.aliasToBean(Sample.class)) return query.list(); 处理客户端收到的消息。