EthernetServer::write()

名称

EthernetServer::write()

説明

サーバに接続しているすべてのクライアントにデータを書く。このとき、データはバイトもしくはバイト列として送信される。

書式

size_t EthernetServer::write(uint8_t b);

size_t EthernetServer::write(const uint8_t *buffer, size_t size)

引数

b書き込むデータ。
bufferデータを格納した配列。
size書き込むデータの大きさ。

戻り値

書き込んだデータのバイト数。これを読みだす必要は必ずしもない。

使用例

 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
33
34
35
36
#include <SPI.h>
#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.

 // the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
//the IP address for the shield:
byte ip[] = { 10, 0, 0, 177 };    
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 0, 0 };

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

void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);

  // 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 == true) {
    // read bytes from the incoming client and write them back
    // to any clients connected to the server:
    server.write(client.read());
  }
}

オリジナルのページ

https://www.arduino.cc/reference/en/libraries/ethernet/server.write/

最終更新日

January 7, 2024

inserted by FC2 system