write()
描述
传送资料到目前与伺服端连线的所有用户端。
语法
server.write(data)
参数
data:要传送到用户端的资料,型态可以为 byte 或 char
回传
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.
