当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Arduino Ethernet - EthernetUDP.endPacket()用法及代码示例


说明

在将 UDP 数据写入远程连接后调用。

用法

EthernetUDP.endPacket();

参数

None

返回

  • 返回一个 int:1 如果数据包发送成功,0 如果有错误

示例

#include <SPI.h>        
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

}

void loop() {

  Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write("hello");
    Udp.endPacket();

}

相关用法


注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Ethernet - EthernetUDP.endPacket()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。