说明
获取远程 UDP 连接的端口。
此函数必须在 UDP.parsePacket() 之后调用。
用法
UDP.remotePort();
参数
None
返回
- int:UDP连接到远程主机的端口
示例
#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;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
}
void loop() {
int packetSize = Udp.parsePacket();
if(packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i =0; i < 4; i++)
{
Serial.print(remote[i], DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBuffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
}
}
相关用法
- Arduino Ethernet - UDP.remoteIP()用法及代码示例
- Arduino Ethernet - server.begin()用法及代码示例
- Arduino Ethernet - EthernetUDP.parsePacket()用法及代码示例
- Arduino Ethernet - Ethernet.setRetransmissionTimeout()用法及代码示例
- Arduino Ethernet - Ethernet.MACAddress()用法及代码示例
- Arduino Ethernet - Ethernet.hardwareStatus()用法及代码示例
- Arduino Ethernet - client.setConnectionTimeout()用法及代码示例
- Arduino Ethernet - client.connected()用法及代码示例
- Arduino Ethernet - EthernetUDP.beginPacket()用法及代码示例
- Arduino Ethernet - EthernetUDP.available()用法及代码示例
- Arduino Ethernet - Ethernet.localIP()用法及代码示例
- Arduino Ethernet - server.available()用法及代码示例
- Arduino Ethernet - EthernetUDP.read()用法及代码示例
- Arduino Ethernet - EthernetUDP.endPacket()用法及代码示例
- Arduino Ethernet - Ethernet.setDnsServerIP()用法及代码示例
- Arduino Ethernet - client.remotePort()用法及代码示例
- Arduino Ethernet - server.accept()用法及代码示例
- Arduino Ethernet - EthernetUDP.begin()用法及代码示例
- Arduino Ethernet - Ethernet.init()用法及代码示例
- Arduino Ethernet - Ethernet.setMACAddress()用法及代码示例
- Arduino Ethernet - if(server)用法及代码示例
- Arduino Ethernet - server.write()用法及代码示例
- Arduino Ethernet - client.available()用法及代码示例
- Arduino Ethernet - EthernetServer()用法及代码示例
- Arduino Ethernet - Ethernet.setSubnetMask()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 Ethernet - UDP.remotePort()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。