EthernetClient::localPort()

名称

EthernetClient::localPort()

説明

クライアントが接続しているローカルポート番号を返却する。

書式

uint16_t EthernetClient::localPort();

引数

なし。

戻り値

クライアントが接続しているローカルポート番号。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10, 0, 0, 177);

// telnet defaults to port 23
EthernetServer server = EthernetServer(23);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // initialize the Ethernet device
  Ethernet.begin(mac, ip);

  // start listening for clients
  server.begin();
}

void loop() {
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client) {
    Serial.print("Client is connected on port: ");
    Serial.println(client.localPort());
    client.stop();
  }
}

オリジナルのページ

https://www.arduino.cc/reference/en/libraries/ethernet/client.localport/

最終更新日

January 7, 2024

inserted by FC2 system