⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cpp

📁 Good example to undrestand of omnet++
💻 CPP
字号:
//
// This file is part of an OMNeT++/OMNEST simulation example.
//
// Copyright (C) 1992-2005 Andras Varga
//
// This file is distributed WITHOUT ANY WARRANTY. See the file
// `license' for details on this and other legal matters.
//


#include "dynapacket_m.h"

/**
 * The server computer; see NED file for more info
 */
class Server : public cSimpleModule
{
  private:
    cModuleType *srvProcType;

  protected:
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);
};

Define_Module(Server);


void Server::initialize()
{
    srvProcType = findModuleType("ServerProcess");
}

void Server::handleMessage(cMessage *msg)
{
    DynaPacket *pk = check_and_cast<DynaPacket *>(msg);

    if (pk->kind()==DYNA_CONN_REQ)
    {
        cModule *mod = srvProcType->createScheduleInit("serverproc",this);
        ev << "DYNA_CONN_REQ: Created process ID=" << mod->id() << endl;
        sendDirect(pk, 0.0, mod, "in");
    }
    else
    {
        int serverProcId = pk->getServerProcId();
        ev << "Redirecting msg to process ID=" << serverProcId << endl;
        cModule *mod = simulation.module(serverProcId);
        if (!mod) {
            ev << " That process already exited, deleting msg\n";
            delete pk;
        } else {
            sendDirect(pk, 0.0, mod, "in");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -