本文整理汇总了C++中UdpSocket::send方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::send方法的具体用法?C++ UdpSocket::send怎么用?C++ UdpSocket::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpSocket
的用法示例。
在下文中一共展示了UdpSocket::send方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main( int argc, char* argv[])
{
if ( argc != 3 )
{
cout << "usage: " << argv[0] << " [localport] [remoteport]" <<
endl;
return 1;
}
int localport = atoi( argv[1] );
int remoteport = atoi( argv[2] );
UdpSocket mySock;
mySock.initialize( localport );
string msg = "herro!";
char msgrx[256];
memset( msgrx, 0, sizeof(msgrx) );
cout << "send returned " << mySock.send( "localhost", remoteport, (unsigned char*)msg.c_str(), msg.length() ) << endl;
cout << "receive returned " << mySock.receive( (unsigned char*)msgrx, sizeof(msgrx) ) << endl;
cout << "received ";
cout << msgrx << endl;
cout << endl;
return 0;
}
示例2: sender
void sender(std::uint16_t port, const std::string &message, bool enableLogging) {
std::vector<std::string> addresses;
getIPV4BroadcastAddresses(addresses);
if(enableLogging) {
for(std::string a : addresses) {
std::cout << a << std::endl;
}
}
UdpSocket socket;
socket.enableBroadcast();
socket.enableReuseAddr();
socket.bind();
Datagram datagram;
datagram.port = port;
std::strcpy(datagram.buffer, message.c_str());
datagram.bufferUsed = message.size() + 1;
while(true) {
for(const std::string address : addresses) {
datagram.address = address;
socket.send(datagram);
}
usleep(1000*1000);
}
}
示例3: run
void run()
{
UdpSocket socket;
char_t buffer[1450];
char_t* pos = buffer;
int32_t networkInt = htonl(mIntValue);
int32_t networkFloat = htonl(*reinterpret_cast<int32_t*>(&mFloatValue));
int32_t strLen = static_cast<int32_t>(mStringValue.getLength());
int32_t netowrkStrlen = htonl(strLen);
Memory::Copy(pos, reinterpret_cast<char_t*>(&networkInt), sizeof(int32_t));
pos += sizeof(int32_t);
Memory::Copy(pos, reinterpret_cast<char_t*>(&netowrkStrlen), sizeof(int32_t));
pos += sizeof(int32_t);
Memory::Copy(pos, mStringValue.c_str(), strLen);
pos += strLen;
Memory::Copy(pos, reinterpret_cast<char_t*>(&networkFloat), sizeof(int32_t));
pos += sizeof(int32_t);
Memory::Copy(pos, reinterpret_cast<char_t*>(&mBoolValue), sizeof(bool_t));
pos += sizeof(bool_t);
socket.send(buffer, static_cast<int32_t>(pos - buffer), "127.0.0.1", mPort);
}
示例4: main
int main(int argc, char* argv[])
{
/* Concept:
1) UdpSocket listens for input data.
2) Data is passed to H264Decoder which than parses
the NALU files and passes everything to ffmpeg.
The decoded data is than passed to the SdlViewer instance;
3) The SdlViewer uses SDL with OpenGL acceleration to show the received frames.
*/
for(int i = 1; i < argc; ++i) {
std::string value(argv[i]);
if (value == "--fullscreen") {
fullscreen = true;
}else if(value == "--oculus"){
viewer = new OculusViewer(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}else if (value == "--help" || value == "-h") {
cout << "--help no idea what exactly this parameter does" << endl
<< "--fullscreen open fullscreen opengl context instead of vga window" << endl
<< "--oculus adjust screen window for Oculus Rift DK2" << endl;
return 0;
}
}
if(viewer == nullptr){
viewer = new SdlViewer(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
input.initClient(cfg.getValueOfKey<string>("TARGET_IP").c_str(), TARGET_PORT);
input.setInitCallback(&init);
input.send(PROTOCOL_TYPE_INIT, nullptr, 0);
viewer->setInputCallback(&inputCallback);
viewer->setPositionCallback(&positionCallback);
viewer->show(fullscreen);
input.send(PROTOCOL_TYPE_CLOSE, nullptr, 0);
input.close();
return 0;
}
示例5: my_send
int my_send()
{
printf("==== Send\n");
char * msg = "hello";
UdpSocket sender;
DataBuffer buffer(1024);
buffer.set_data_size(1024);
buffer.set_data((YETI_Byte *)msg, strlen(msg));
IpAddress address;
address.resolve_name("localhost");
SocketAddress socket_address(address, 9123);
YETI_Result result = sender.send(buffer, &socket_address);
if (YETI_FAILED(result)) {
fprintf(stderr, "send() failed (%d)\n", result);
return result;
}
return 0;
}
示例6: exec
void PTracker::exec(const ObjectSensorReading& visualReading)
{
static UdpSocket senderSocket;
vector<ObjectSensorReading> observations;
string dataToSend;
int ret;
#ifdef DEBUG_MODE
INFO("[PTracker (" << agentId << ")] - ***********************************" << endl);
INFO("[PTracker (" << agentId << ")] - \tNEW ITERATION (" << ++counterResult << ")" << endl);
INFO("[PTracker (" << agentId << ")] - ***********************************" << endl);
#else
INFO(".");
#endif
currentTimestamp.setToNow();
updateTargetVector(visualReading);
agentPose.x = 0.0;
agentPose.y = 0.0;
agentPose.theta = 0.0;
objectSensorReading.setObservationsAgentPose(agentPose);
objectSensorReading.setObservations(targetVector,currentTargetIndex,lastCurrentTargetIndex,LAST_N_TARGET_PERCEPTIONS,worldX,worldY);
observations.push_back(objectSensorReading);
processor.processReading(agentPose,initialTimestamp,currentTimestamp,observations);
const EstimationsSingleAgent& estimationsWithModel = objectParticleFilter.getEstimationsWithModel();
updateTargetPosition(estimationsWithModel);
bestParticles = updateBestParticles(estimationsWithModel);
if (estimatedTargetModels.size() > 0)
{
dataToSend = "Agent ";
AgentPacket agentPacket;
agentPacket.dataPacket.ip = agentAddress;
agentPacket.dataPacket.port = agentPort;
agentPacket.dataPacket.agentPose = agentPose;
agentPacket.dataPacket.estimatedTargetModels = estimatedTargetModels;
agentPacket.dataPacket.particlesTimestamp = currentTimestamp.getMsFromMidnight();
dataToSend += agentPacket.toString();
if ((Timestamp() - lastTimeInformationSent).getMs() > (1000.0 / messageFrequency))
{
sendEstimationsToAgents(dataToSend);
lastTimeInformationSent.setToNow();
}
ObjectSensorReadingMultiAgent objectSensorReadingMultiAgent;
objectSensorReadingMultiAgent.setAgent(agentAddress,agentPort);
objectSensorReadingMultiAgent.setSensor(objectParticleFilter.getSensor());
objectSensorReadingMultiAgent.setEstimationsWithModels(estimatedTargetModels);
objectSensorReadingMultiAgent.setEstimationsTimestamp(currentTimestamp.getMsFromMidnight());
mutex.lock();
observationsMultiAgent.push_back(objectSensorReadingMultiAgent);
mutex.unlock();
}
initialTimestamp = currentTimestamp;
++iterationCounter;
if (iterationCounter == 1)
{
iterationCounter = 0;
initialTimestampMas = currentTimestamp;
mutex.lock();
multiAgentProcessor.processReading(observationsMultiAgent);
estimatedTargetModelsMultiAgent = objectParticleFilterMultiAgent.getEstimationsWithModel();
observationsMultiAgent.clear();
mutex.unlock();
dataToSend = prepareDataForViewer();
ret = senderSocket.send(dataToSend,InetAddress(pViewerAddress,pViewerPort));
if (ret == -1)
{
ERR("Error when sending message to PViewer." << endl);
}
if (rosBridgeEnabled)
{
stringstream s;
//.........这里部分代码省略.........
示例7: client_handler
void* client_handler(void* _sockfd)
{
char* buf = 0;
int len;
uint16_t tcplen;
TcpMessage msg(mode);
// setup udp socket
UdpMessage udpMsg;
debug("Get connection from client, start authentication.");
int sockfd = reinterpret_cast<long>(_sockfd);
Connection conn(sockfd);
// Get A0 command
{
debug("Get A0 command from client");
tcplen = conn.recv_uint16();
buf = (char*) malloc(tcplen);
msg.len = tcplen;
len = conn.recv(buf + 2, tcplen - 2);
msg.deserialize(buf, tcplen);
free(buf);
// the user is not in the user database, close the TCP connection
if (users.find(msg.cmd.user) == users.end())
{
info(
"The user <%s> is not found in user database, close the connection with client",
msg.cmd.user.c_str());
// the de-constructor of conn will close the socket
return 0;
}
}
{
// A1 command: A1 32bit-random-number
debug("Send A1 command to client");
msg.cmd.step = 1;
buf = (char*) malloc(msg.length());
len = msg.serialize(buf);
conn.send(buf, len);
free(buf);
// A1 command -- end
}
{
debug("Get A2 command from client");
tcplen = conn.recv_uint16();
msg.len = tcplen;
buf = (char*) malloc(tcplen);
len = conn.recv(buf + 2, tcplen - 2);
msg.deserialize(buf, len);
free(buf);
}
UdpSocket udpSkt;
{
debug("Send A3 command to client");
msg.cmd.step = 3;
msg.cmd.status = 0;
buf = (char*) malloc(msg.length());
if (mode == '1')
{
std::string passwd = users[msg.cmd.user];
char sha[128];
get_sha256(sha, passwd, msg.cmd.rn);
if (strncmp(sha, msg.cmd.sha, 64) == 0)
{
msg.cmd.status = 0;
}
else
{
msg.cmd.status = 1;
}
}
// if auth successfully, setup UDP for query
if (msg.cmd.status == 0)
{
msg.cmd.sid = udpSkt.get_port(); // should be udp port
info("User Authentication done for <%s>.", msg.cmd.user.c_str());
//.........这里部分代码省略.........