本文整理汇总了C++中UDP类的典型用法代码示例。如果您正苦于以下问题:C++ UDP类的具体用法?C++ UDP怎么用?C++ UDP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UDP类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: UDP
////////////////////////////////////////////////////////////////////////////////////
///
/// \brief Creates a connection to the JAUS component given the provided data
/// if possible.
///
/// \param[in] id JAUS component ID.
/// \param[in] destination Destination information for connection creation.
///
/// \return Pointer to new connection on success, false on failure.
///
////////////////////////////////////////////////////////////////////////////////////
Connection* UDP::CreateConnection(const Address& id,
const Info* destination)
{
CxUtils::UdpSocket* primary = dynamic_cast<CxUtils::UdpSocket*>( ( (CxUtils::Socket*)mpSocket) );
// Only port that has reserved the JUDP port can create UDP connections.
if(primary == NULL || primary->GetSourcePort() != this->mParameters.mDestPortNumber)
{
return NULL;
}
UDP* newUDP = new UDP(mSingleThreadModeFlag);
newUDP->mID = id;
newUDP->CopyConnectionData(this);
newUDP->mParameters = mParameters;
newUDP->mParameters = *destination;
newUDP->mParameters.mClientFlag = true;
newUDP->mpSocket = primary->CreateNewDestination(destination->mDestIP, destination->mDestPortNumber);
if(newUDP->Initialize(&newUDP->mParameters))
{
return newUDP;
}
else
{
delete newUDP;
}
return NULL;
}
开发者ID:ShowLove,项目名称:Robotics_Club,代码行数:40,代码来源:udp.cpp
示例2: dojoin
//function used to communicate with the sequencer so as to join the chat group.
int chatClient::dojoin(string rs_ip, int rs_port){
string outmsg;
int outlen, saddr_len;
s_ip = rs_ip;
s_port = rs_port;
//setupt the UDP socket
UDP joinUDP;
joinUDP.setRemoteAddr(s_ip.c_str(),s_port);
//args: sequencer's ip, port, myIP, myPort,myName;
myMsg message = mmaker.makeJoin(name);
msgMaker::serialize(outmsg, outlen, message);
if(joinUDP.sendToNACK(outmsg.c_str(),outlen)==-2){
cerr<<"Error! Not able to join to the group... App is about to exit..."
<<endl;
exit(-1);
}
return 1;
}
开发者ID:x-y-z,项目名称:Distributed-Chat,代码行数:26,代码来源:chatClient.cpp
示例3: callback
bool callback(const PDU &pdu)
{
// The packet probably looks like this:
//
// EthernetII / IP / UDP / RawPDU
//
// So we retrieve each layer, and construct a
// DNS PDU from the RawPDU layer contents.
EthernetII eth = pdu.rfind_pdu<EthernetII>();
IP ip = eth.rfind_pdu<IP>();
UDP udp = ip.rfind_pdu<UDP>();
DNS dns = udp.rfind_pdu<RawPDU>().to<DNS>();
// Is it a DNS query?
if(dns.type() == DNS::QUERY) {
// Let's see if there's any query for an "A" record.
for(const auto &query : dns.queries()) {
if(query.type() == DNS::A) {
// Here's one! Let's add an answer.
dns.add_answer(
DNS::Resource(
query.dname(),
"127.0.0.1",
DNS::A,
query.query_class(),
// 777 is just a random TTL
777
)
);
}
}
// Have we added some answers?
if(dns.answers_count() > 0) {
// It's a response now
dns.type(DNS::RESPONSE);
// Recursion is available(just in case)
dns.recursion_available(1);
// Build our packet
auto pkt = EthernetII(eth.src_addr(), eth.dst_addr()) /
IP(ip.src_addr(), ip.dst_addr()) /
UDP(udp.sport(), udp.dport()) /
dns;
// Send it!
sender.send(pkt);
}
}
return true;
}
开发者ID:lodagro,项目名称:libtins.github.io,代码行数:48,代码来源:dns-spoof.cpp
示例4: TEST_F
TEST_F(MatchesResponseTest, DHCP) {
uint8_t dhcp_discover[] = {
255, 255, 255, 255, 255, 255, 0, 1, 1, 0, 0, 1, 8, 0, 69, 0, 1,
25, 77, 62, 0, 0, 64, 17, 44, 151, 0, 0, 0, 0, 255, 255, 255,
255, 0, 68, 0, 67, 1, 5, 0, 0, 1, 1, 6, 0, 217, 7, 133, 224, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 99, 130, 83, 99, 53, 1, 1, 61, 7, 1, 0, 1, 1,
0, 0, 1, 255
};
uint8_t dhcp_offer[] = {
0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 2, 8, 0, 69, 0, 1, 28, 221, 161,
0, 0, 64, 17, 158, 45, 127, 0, 0, 1, 127, 0, 0, 1, 0, 67, 0, 68,
1, 8, 0, 0, 2, 1, 6, 0, 217, 7, 133, 224, 0, 0, 0, 0, 0, 0, 0, 0,
127, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
99, 130, 83, 99, 53, 1, 2, 54, 4, 127, 0, 0, 1, 51, 4, 0, 0, 1,
44, 255
};
EthernetII discover(dhcp_discover, sizeof(dhcp_discover));
UDP *udp = discover.find_pdu<UDP>();
const RawPDU *raw = discover.find_pdu<RawPDU>();
ASSERT_TRUE(udp != NULL);
ASSERT_TRUE(raw != NULL);
udp->inner_pdu(raw->to<DHCP>());
EXPECT_TRUE(discover.matches_response(dhcp_offer, sizeof(dhcp_offer)));
EXPECT_FALSE(discover.matches_response(dhcp_discover, sizeof(dhcp_discover)));
}
开发者ID:Imva,项目名称:libtins,代码行数:47,代码来源:matches_response.cpp
示例5: loop
void loop() {
if (WiFi.ready()) {
if (firstTimeReady) {
firstTimeReady = false;
// First time we get WiFi.ready(), initialize the UDP listener. This happens
// every time we reconnect to WiFi.
mcastUdp.begin(MCAST_PORT);
}
if (!haveServerAddr && millis() - serverAddrLastCheck >= SERVER_ADDR_CHECK_RETRY_MS) {
serverAddrLastCheck = millis();
// If we don't have a server IP address, request it periodically (every 20 seconds)
Serial.printlnf("requesting server address at %s:%d", mcastAddr.toString().c_str(), MCAST_PORT);
strcpy(udpBuffer, "\n");
mcastUdp.sendPacket(udpBuffer, strlen(udpBuffer), mcastAddr, MCAST_PORT);
}
int count = mcastUdp.receivePacket(udpBuffer, UDP_BUFFER_SIZE - 1);
if (count > 0) {
udpBuffer[count] = 0;
// Handle a received UDP packet from the server with the IP address and port of the server
int addr[4], port;
if (sscanf(udpBuffer, "%u.%u.%u.%u:%u", &addr[0], &addr[1], &addr[2], &addr[3], &port) == 5) {
serverAddr = IPAddress(addr[0], addr[1], addr[2], addr[3]);
serverPort = port;
haveServerAddr = true;
Serial.printlnf("serverAddr=%s port=%d", serverAddr.toString().c_str(), serverPort);
}
}
}
else {
// If WiFi disconnects, we need to reestablish listeners next time
firstTimeReady = true;
}
}
开发者ID:rickkas7,项目名称:serverlocator,代码行数:42,代码来源:cmcastserverlocator.cpp
示例6: openSocket
void openSocket() {
udp.stop();
// Get OpenThread interface index (OpenThread interface is named "th1" on all Mesh devices)
uint8_t idx = 0;
if_name_to_index("th1", &idx);
Log.trace("th1 index = %u", idx);
// Create UDP socket and bind to OpenThread interface
auto ur = udp.begin(PORT, idx);
Log.trace("UDP.begin() = %u", ur);
// Subscribe to ff03::1:1001
HAL_IPAddress addr = {};
addr.v = 6;
inet_inet_pton(AF_INET6, MULTICAST_ADDR, addr.ipv6);
mcastAddr = addr;
int r = udp.joinMulticast(mcastAddr);
Log.trace("Subscribed to %s: %d", MULTICAST_ADDR, r);
}
开发者ID:spark,项目名称:firmware,代码行数:21,代码来源:application.cpp
示例7: sendUDPmessage
//
// UDP stuff
//
void sendUDPmessage( String msg, int port = 5100 )
{
IPAddress multicast( 225, 1, 1, 1 );
UDP server;
if ( server.begin( port ) )
{
server.beginPacket( multicast, port );
server.write( msg );
server.endPacket();
server.stop();
}
}
开发者ID:lemontongs,项目名称:AllSpark,代码行数:17,代码来源:main.cpp
示例8: parseMacAddress
int WolClient::wake(const char* mac) {
uint8_t contents[MAGIC_HEADER_LENGTH + REPEAT_MAC * MAC_BYTES];
uint8_t rawMac[MAC_BYTES];
parseMacAddress(mac, rawMac);
UDP udp;
udp.begin(port);
udp.beginPacket(broadcastIP, port);
for (int i = 0; i < MAGIC_HEADER_LENGTH; i++) {
contents[i] = 0xFF;
}
for (uint8_t i = MAGIC_HEADER_LENGTH; i < sizeof contents; i++) {
contents[i] = rawMac[(i - MAGIC_HEADER_LENGTH) % MAC_BYTES];
}
udp.write(contents, sizeof contents);
udp.endPacket();
udp.stop();
return TRUE;
}
开发者ID:massivezz,项目名称:nora,代码行数:24,代码来源:wol_client.cpp
示例9: TEST_F
TEST_F(UDPTest, DefaultContructor) {
UDP udp;
EXPECT_EQ(udp.dport(), 0);
EXPECT_EQ(udp.sport(), 0);
EXPECT_FALSE(udp.inner_pdu());
}
开发者ID:JeanJoskin,项目名称:libtins,代码行数:6,代码来源:udp.cpp
示例10: test_equals
void UDPTest::test_equals(const UDP& udp1, const UDP& udp2) {
EXPECT_EQ(udp1.dport(), udp2.dport());
EXPECT_EQ(udp1.sport(), udp2.sport());
EXPECT_EQ(udp1.length(), udp2.length());
EXPECT_EQ(udp1.size(), udp2.size());
EXPECT_EQ(udp1.header_size(), udp2.header_size());
EXPECT_EQ(bool(udp1.inner_pdu()), bool(udp2.inner_pdu()));
}
开发者ID:JeanJoskin,项目名称:libtins,代码行数:8,代码来源:udp.cpp
示例11: Serialize
void HapiliMessage::Serialize(UDP& to) {
to.write((byte*)&header, sizeof(Header));
}
开发者ID:amitgiri0001,项目名称:hapili,代码行数:3,代码来源:HapiliMessage.cpp
示例12: parser
//fuction actually used to process the message.
//it will analyze the header of the message and take actions accordingly.
int chatClient::processMSG(const char* msg, int mlen)
{
peer newUser;
string newName, newIP, textmsg, outmsg;
int newPort, newID;
int outlen,i;
int seqNum =0;
myMsg tempMsg;
vector<peer>::iterator aIter;
msgParser parser(msg, mlen);
if(parser.isACK()){
//return 0;
//since all the UDP_ACKs are handled in the underlaying UDP-wrapper layer, we simply
//ignore the this message.
}
else{
switch (parser.msgTypeIs()) {
case join:
if(status!=ELEC){
status=NORMAL;
//setup and send a Navi message
mmaker.setInfo(sname,s_ip, s_port,s_id);
tempMsg = mmaker.makeNavi();
msgMaker::serialize(outmsg,outlen,tempMsg);
parser.senderInfo(newIP,newName,newPort,newID);
UDP joinUDP;
joinUDP.setRemoteAddr(newIP.c_str(),newPort);
joinUDP.sendToNACK(outmsg.c_str(),outlen);
mmaker.setInfo(name,IP, port,C_ID);
return 1;
}
else{
//receive a Join request message during the election,
//push it into message queue and
//handle it later on.
inMsgQ.push(msg);
return 1;
}
break;
case navi:
//the chatClient get a navi message, which means the one
//he asked is not the sequencer, and the info of the
//sequencer is returned via this message.
//get the info of the sequencer and send another join
//message to it.
parser.senderInfo(newIP, newName, newPort,newID);
dojoin(newIP, newPort);
return 1;
break;
case join_ack:
//get the peerlist and client_id decided by the sequencer
//and store them locally for future use.
parser.joinFeedback(msgMaxCnt, C_ID, clientList);
parser.senderInfo(newIP,newName,newPort,newID);
s_id = newID;
s_ip = newIP;
s_port = newPort;
sname = newName;
clntUDP.setRemoteAddr(s_ip.c_str(), s_port);
//call the setInfo again so as to set the C_ID field
mmaker.setInfo(name,IP, port,C_ID);
displayClients();
status = NORMAL;
return 1;
break;
case join_broadcast:
//get the ip ,port name and client ID of the new user
//and store them locally.
if(status!=ELEC){
status=NORMAL;
parser.senderInfo(newIP, newName, newPort, newID);
if(newID==C_ID){
return 1;
}
parser.joinName(newName);
memset(&newUser, 0, sizeof(peer));
memcpy(newUser.name,newName.c_str(),newName.size());
memcpy(newUser.ip, newIP.c_str(), newIP.size());
newUser.c_id = newID;
newUser.port = newPort;
clientList.push_back(newUser);
cout<<"NOTICE "<<newUser.name<<" joined on "
<<newUser.ip<<":"<<newUser.port<<endl;
return 1;
}
else{
//in wrong state, push the message into message queue
//and handle later on
cerr<<"Unexpected Join Broadcast message @"<<name
<<" !"<<endl;
//.........这里部分代码省略.........
开发者ID:x-y-z,项目名称:Distributed-Chat,代码行数:101,代码来源:chatClient.cpp
示例13: main
int main(void)
{
setup();
while(1)
{
if(udp1.recv(buf))
{
uart1.printf("\r\n============================");
uart1.printf("\r\n本地端口:%d", udp1.localPort );
uart1.printf("\r\n消息来源:%d.%d.%d.%d:%d", udp1.remoteIP[0], udp1.remoteIP[1], udp1.remoteIP[2], udp1.remoteIP[3], udp1.remotePort);
uart1.printf("\r\n数据内容:");
uart1.printf((const char *)buf);
udp1.sendto(udp1.remoteIP, udp1.remotePort, buf, 100);
}
if(udp2.recv(buf))
{
uart1.printf("\r\n============================");
uart1.printf("\r\n本地端口:%d", udp2.localPort );
uart1.printf("\r\n消息来源:%d.%d.%d.%d:%d", udp2.remoteIP[0], udp2.remoteIP[1], udp2.remoteIP[2], udp2.remoteIP[3], udp2.remotePort);
uart1.printf("\r\n数据内容:");
uart1.printf((const char *)buf);
udp2.sendto(udp2.remoteIP, udp2.remotePort, buf, 100);
}
}
}
开发者ID:0x1abin,项目名称:ebox_stm32,代码行数:30,代码来源:1.ucp.cpp
示例14: main
int main(void)
{
setup();
while(1)
{
if(udp.recv(recvBuf))
{
uart1.printf("\r\n============================");
uart1.printf("\r\n本地端口:%d",udp.localPort );
uart1.printf("\r\n消息来源:%d.%d.%d.%d:%d", udp.remoteIP[0],udp.remoteIP[1],udp.remoteIP[2],udp.remoteIP[3],udp.remotePort);
uart1.printf("\r\n数据长度:%d",len);
uart1.printf("\r\n数据内容:");
uart1.printf((const char *)recvBuf);
udp.sendto(udp.remoteIP,udp.remotePort,recvBuf,100);
}
// udp.sendto(rip,8080,data,60);
// delay_ms(500);
}
}
开发者ID:shentqlf,项目名称:myboot,代码行数:29,代码来源:E_UDP_Interrupt.cpp
示例15: main
int main(void)
{
setup();
while(1)
{
res=f_opendir(&DirObject,"/123");//打开目录
if(res==FR_OK)
{
uart1.printf("\r\n打开目录成功 !\r\n");
uart1.printf("该目录所在簇号:%d\r\n",DirObject.clust);
uart1.printf("该目录所在扇区号:%d\r\n",DirObject.sect);
}
else if(res==FR_NO_PATH)
uart1.printf("所找目录路径不存在\r\n");
else
uart1.printf("打开目录失败~~~~(>_<)~~~~ \r\n");
if(udp1.recv(buf))
{
uart1.printf("\r\n============================");
uart1.printf("\r\n本地端口:%d",udp1.localPort );
uart1.printf("\r\n消息来源:%d.%d.%d.%d:%d", udp1.remoteIP[0],udp1.remoteIP[1],udp1.remoteIP[2],udp1.remoteIP[3],udp1.remotePort);
uart1.printf("\r\n数据内容:");
uart1.printf((const char *)buf);
uart1.printf("\r\n============================");
udp1.sendto(udp1.remoteIP,udp1.remotePort,buf,100);
}
delay_ms(1000);
}
}
开发者ID:Hletian,项目名称:ebox_stm32,代码行数:31,代码来源:fat_net.cpp
示例16: setup
void setup()
{
ebox_init();
uart1.begin(115200);
uart1.printf("\r\nuart1 9600 ok!");
w5500.begin(2, mac, lip, sub, gw, dns);
attach_eth_to_socket(&w5500);
w5500.getMAC (ip);
uart1.printf("\r\nmac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5]);
w5500.getIP (ip);
uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
w5500.getSubnet(ip);
uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
w5500.getGateway(ip);
uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
uart1.printf("Network is ready.\r\n");
if(udp1.begin(0, 30000) == 0)
uart1.printf("\r\nudp1 server creat ok! listen on 30000");
if(udp2.begin(1, 30001) == 0)
uart1.printf("\r\nudp2 server creat ok! listen on 30001");
}
开发者ID:0x1abin,项目名称:ebox_stm32,代码行数:26,代码来源:1.ucp.cpp
示例17: setup
void setup() {
// Set the port whis to use for contactign us back
Udp.begin(8888);
// Sedn the message to the server
if (Udp.sendPacket(buffer, 39, remoteIP, port) < 0) {
Particle.publish("Error");
}
}
开发者ID:eliot-akira,项目名称:IoT-Raw-Sockets-Examples,代码行数:13,代码来源:udpParticleClient.cpp
示例18: loop
void loop() {
// First we need to parse before we can check avaiability.
Udp.parsePacket();
// While there is data, we display it.
while(Udp.available()) {
// Read first char of data received
char c = Udp.read();
// Print all the char one by one.
Serial.print(c);
}
}
开发者ID:eliot-akira,项目名称:IoT-Raw-Sockets-Examples,代码行数:16,代码来源:udpParticleClient.cpp
示例19: setup
void setup()
{
ebox_init();
uart1.begin(9600);
ret = sd.begin();
if(!ret)
uart1.printf("\r\nsdcard init ok!");
f_mount(0, &fs);
w5500.begin(mac,lip,sub,gw);
attachEthToSocket(&w5500);
attachSDCardToFat(&sd);
w5500.getMAC (ip);
uart1.printf("\r\nmac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0],ip[1],ip[2],ip[3],ip[4],ip[5]);
w5500.getIP (ip);
uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
w5500.getSubnet(ip);
uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
w5500.getGateway(ip);
uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]);
uart1.printf("Network is ready.\r\n");
if(udp1.begin(0,30000) == 0)
uart1.printf("\r\nudp1 server creat ok! listen on 30000");
uart1.printf("\r\nret = %d",ret);
ret = sd.getCID(buf);
uart1.printf("\r\nret = %d",ret);
uart1.printf((const char*)buf);
ret = sd.getCSD(buf);
uart1.printf("\r\nret = %d",ret);
rl = sd.getCapacity();
x = (float)rl;
uart1.printf("\r\n容量 = %f",x/1024/1024);
res=f_getfree("/",&free_clust,&fss);
uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize));
if(res==FR_OK)
{
uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize));
uart1.printf("该分区大小为:%dM\r\n",(fss->max_clust-2)*(fss->csize)/2048);
uart1.printf("该分区空簇数为:%d\r\n",free_clust);
uart1.printf("该分区空扇区数为:%d\r\n",free_clust*(fss->csize));
}
else
uart1.printf("获取分区空簇失败\r\n,res = %d",res);
uart1.printf("\r\n");
}
开发者ID:Hletian,项目名称:ebox_stm32,代码行数:54,代码来源:fat_net.cpp
示例20: loop
/* executes continuously after setup() runs */
void loop() {
static system_tick_t last = 0;
ssize_t s = udp.receivePacket(buf, sizeof(buf));
if (s > 0) {
char tmp[IP_ADDR_STRLEN_MAX] = {};
auto ip = udp.remoteIP();
Log.trace("Received %d bytes from %s#%u", s,
inet_inet_ntop(AF_INET6, ip.raw().ipv6, tmp, sizeof(tmp)), udp.remotePort());
}
if ((millis() - last) >= PERIOD) {
size_t len = random(1, sizeof(buf));
rng.gen((char*)buf, len);
auto r = udp.sendPacket(buf, len, mcastAddr, PORT);
Log.trace("Sent %u bytes to %s#%u : %d %d", len, MULTICAST_ADDR, PORT, r, errno);
last = millis();
if (r < 0) {
openSocket();
}
}
}
开发者ID:spark,项目名称:firmware,代码行数:22,代码来源:application.cpp
注:本文中的UDP类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论