stop()
描述
中断与伺服端的连线。
语法
client.stop()
参数
无参数
回传
无回传值
范例
/*
这个范例连线到 "http://arduino.cc/",把该网页下载后输出到序列埠监控视窗
*/
// 函式库
#include <GSM.h>
// PIN 码
#define PINNUMBER ""
// APN 资料
#define GPRS_APN "GPRS_APN" // 用你的 APN 取代
#define GPRS_LOGIN "login" // 用你的使用者名称取代
#define GPRS_PASSWORD "password" // 用你的密码取代
// 初始化函式库
GSMClient client;
GPRS gprs;
GSM gsmAccess;
// 网址(URL)
char server[] = "arduino.cc";
char path[] = "/";
int port = 80;
void setup()
{
// 初始化 Serial
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// 连线状态
boolean notConnected = true;
// 启动 Arduino GSM shield,如果你的 SIM 卡有 PIN 码,请当作 begin() 的参数
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// 检查是否成功连线
if (client.connect(server, port))
{
Serial.println("connected");
// HTTP 请求
client.print("GET ");
client.print(path);
client.println(" HTTP/1.0");
client.println();
}
else
{
// 如果没有成功连线,印出错误讯息
Serial.println("connection failed");
}
}
void loop()
{
// 如果伺服端有传送资料,读取资料并且输出到序列埠监控视窗
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// 如果与伺服端的连线中断了,关闭用户端
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// 不做任何事
for(;;)
;
}
}
See also
- GSMClient
- ready()
- connect()
- beginWrite()
- write()
- endWrite()
- connected()
- read()
- available()
- peek()
- flush()
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.
