C Socket 和 Omnet++ 之间的方法名称冲突
Collision of method name between C Socket & Omnet++
我想在用 Omnet++ 完成的网络模拟中使用套接字,我在以下两者之间遇到方法名称冲突:
- 套接字的 send() 方法。
- 由 Omnet++ 定义的 send() 方法,允许模拟模块之间的味精交换。
编译器仅识别由 Omnet++ 定义的 send() 方法。
我该如何解决它?
谢谢
编辑
为了更清楚,我将通过我的代码副本:
GeoTraCIMobility.cc(CPP代码)
#include <limits>
#include <iostream>
#include <sstream>
//#include <cstring> // Needed for memset
//#include <sys/socket.h> // Needed for the socket functions
//#include <netdb.h> // Needed for the socket functions
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "mobility/geoTraCI/GeoTraCIMobility.h"
Define_Module(GeoTraCIMobility);
namespace {
const double MY_INFINITY = (std::numeric_limits<double>::has_infinity ? std::numeric_limits<double>::infinity() : std::numeric_limits<double>::max());
double roadIdAsDouble(std::string road_id) {
std::istringstream iss(road_id);
double d;
if (!(iss >> d)) return MY_INFINITY;
return d;
}
}
void GeoTraCIMobility::Statistics::initialize()
{
firstRoadNumber = MY_INFINITY;
startTime = simTime();
totalTime = 0;
stopTime = 0;
minSpeed = MY_INFINITY;
maxSpeed = -MY_INFINITY;
totalDistance = 0;
totalCO2Emission = 0;
}
//OTHERS FUNCTIONS
// Function that create a socket and send data
void GeoTraCIMobility::requestingFromPyServer()
{
std::string HOST = "127.0.0.1";
int PORT = 19999;
int MAX_BUFFER = 1024;
int connectionFd, rc, index = 0, limit = MAX_BUFFER;
struct sockaddr_in servAddr, localAddr;
char buffer[MAX_BUFFER+1];
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = AF_INET;
servAddr.sin_port = htons(PORT);
servAddr.sin_addr.s_addr = inet_addr(HOST.c_str());
// Create socket
connectionFd = socket(AF_INET, SOCK_STREAM, 0);
/* bind any port number */
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
localAddr.sin_port = htons(0);
rc = bind(connectionFd,
(struct sockaddr *) &localAddr, sizeof(localAddr));
// Connect to Server
connect(connectionFd,
(struct sockaddr *)&servAddr, sizeof(servAddr));
// Send request to Server
std::string req= "ShortestPath_297162704_82660198";
sprintf( buffer, "%s", req.c_str() );
// UNRECOGNIZED SEND METHOD
send(connectionFd, buffer, strlen(buffer), 0 );
// UNRECOGNIZED SEND METHOD
close(connectionFd);
printf("Client closed.n");
}
GeoTraCIMobility.cc 从 cSimpleModule 继承了以下发送方法:
cSimpleModule.h
/**
* Sends a message through the gate given with its ID.
*/
int send(cMessage *msg, int gateid) {return sendDelayed(msg, SIMTIME_ZERO, gateid);}
/**
* Sends a message through the gate given with its name and index
* (if multiple gate).
*/
int send(cMessage *msg, const char *gatename, int gateindex=-1) {return sendDelayed(msg, SIMTIME_ZERO, gatename, gateindex);}
/**
* Sends a message through the gate given with its pointer.
*/
int send(cMessage *msg, cGate *outputgate) {return sendDelayed(msg, SIMTIME_ZERO, outputgate);}
使用 ::send(...)
访问 OMNeT++ 模型中的全局函数。否则,将调用从 cSimpleModule 固有的 send()
方法。
相关文章:
- 工厂方法中的访问冲突
- 具有相同名称的方法和内部类(错误:.. 与前面的声明冲突)
- 可视模板参数名称与 MSVC C++中的方法冲突
- C Socket 和 Omnet++ 之间的方法名称冲突
- 相互冲突名称的成员变量和方法变量
- Box2d C++访问冲突使用b2fixture超出方法
- 超级方法调用中的C++名称冲突
- 我应该如何处理类型而不是方法的多重继承冲突
- 调用基类的方法时发生访问冲突
- 宏和方法之间可能存在的冲突
- 如何解决调用 dll 方法时的访问冲突写入位置
- 解决运行时库冲突的好方法是什么?
- 宏定义的tcl-8.5.12和qt-4.7.4中的方法之间的冲突
- Valgrind:getter方法中包含rdlock的线程加载冲突
- Arduino方法名称与库函数冲突
- c++中返回类型名称与方法名称冲突
- 在鼠标钩子代码中调用方法会导致访问冲突
- 访问dll方法时的访问冲突读取位置
- 访问冲突直接x更新方法
- 错误:JNI方法的类型冲突