说明
从文件中读取一个字节而不前进到下一个。也就是说,对peek() 的连续调用将返回相同的值,下一次对read() 的调用也将返回相同的值。
此函数继承自 Stream 类。有关详细信息,请参阅 Stream 类主页。
用法
server.peek()
参数
- None
返回
- b:下一个字节或字符
- -1:如果没有可用
示例
…
#include <SPI.h>
#include <WiFiNINA.h>
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Serial.begin(9600);
while (!Serial) {
}
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
server.begin();
}
void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
int i = 0;
while (client.connected()) {
if (client.available()) {
char c = client.peek();
Serial.print("peek: ");
Serial.println(c);
Serial.print("calling a second time peek, the char is the same: ");
c = client.peek();
Serial.println(c);
Serial.print("calling the read retry the char and erase from the buffer: ");
c = client.read();
Serial.println(c);
if (i == 2) {
while (1);
}
i++;
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
…
相关用法
- Arduino WiFiNINA - server.status()用法及代码示例
- Arduino WiFiNINA - server.available()用法及代码示例
- Arduino WiFiNINA - server.write()用法及代码示例
- Arduino WiFiNINA - server.begin()用法及代码示例
- Arduino WiFiNINA - WiFi.config()用法及代码示例
- Arduino WiFiNINA - WiFi.encryptionType()用法及代码示例
- Arduino WiFiNINA - WiFi.gatewayIP()用法及代码示例
- Arduino WiFiNINA - WiFi.BSSID()用法及代码示例
- Arduino WiFiNINA - WiFi.begin()用法及代码示例
- Arduino WiFiNINA - client.connected()用法及代码示例
- Arduino WiFiNINA - WiFi.RSSI()用法及代码示例
- Arduino WiFiNINA - WiFi.channel()用法及代码示例
- Arduino WiFiNINA - WiFi.setTimeout()用法及代码示例
- Arduino WiFiNINA - WiFi.scanNetworks()用法及代码示例
- Arduino WiFiNINA - WiFiSSLClient用法及代码示例
- Arduino WiFiNINA - WiFi.localIP()用法及代码示例
- Arduino WiFiNINA - client.connectSSL()用法及代码示例
- Arduino WiFiNINA - WiFi.beginAP()用法及代码示例
- Arduino WiFiNINA - client.connect()用法及代码示例
- Arduino WiFiNINA - client.available()用法及代码示例
- Arduino WiFiNINA - WiFi.setHostname()用法及代码示例
- Arduino WiFiNINA - WiFi.hostByName()用法及代码示例
- Arduino WiFiNINA - WiFi.firmwareVersion()用法及代码示例
- Arduino WiFiNINA - client.status()用法及代码示例
- Arduino WiFiNINA - WiFi.reasonCode()用法及代码示例
注:本文由纯净天空筛选整理自arduino.cc大神的英文原创作品 WiFiNINA - server.peek()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。