write()

描述

傳送資料到目前與伺服端連線的所有用戶端。

語法


server.write(data)

參數

data:要傳送到用戶端的資料,型態可以為 bytechar

回傳

byte:回傳 write() 傳送至用戶端的位元組數量

範例

#include <WiFi.h>

char ssid[] = "yourNetwork";
char pass[] = "yourPassword";
int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
  // 初始化序列埠
  Serial.begin(9600);
  Serial.println("Attempting to connect to WPA network...");
  Serial.print("SSID: ");
  Serial.println(ssid);

  status = WiFi.begin(ssid, pass);
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    while(true);
  } 
  else {
    server.begin();
  }
}

void loop() {
  // 監聽是否有用戶端傳送請求
  WiFiClient client = server.available();
  if (client == true) {
    // 從用戶端讀取資料並且把該資料傳送到所有與伺服端連線的用戶端
    server.write(client.read());
  }
}

函式庫參考主頁面

The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.