WiFiServer Class

WiFiServer Class

Description
A class of WiFi server implementation for Ameba.

Syntax
class WiFiServer

Members

Public Constructors 
WiFiServer::WiFiServerConstructs a WiFiServer object and creates a server that listens for incoming connections on the specified port.
Public Methods 
WiFiServer::availableGets a client that is connected to the server and has data available for reading.
WiFiServer::beginServer start listening for incoming connections.
WiFiServer::connectedCheck if Server is still connected.
WiFiServer::closeDisconnect the server.
WiFiServer::endDisconnect the server.
WiFiServer::recvRead the received byte from the server.
WiFiServer::setTimeoutSet the amount of time the server can take to send data to the client.
WiFiServer::stopDisconnect the server.
WiFiServer::writeWrite data to all the clients connected to a server.
WiFiServer::enableIPv6Enable IPv6 Usage.
WiFiServer::getIPv6StatusReturn current IPv6 enable status.

WiFiServer::WiFiServer

Description
Constructs a WiFiServer object and creates a server that listens for incoming connections on the specified port.

Syntax
WiFiServer (uint16_t port);

Parameters
port: The port number being connected to.

Returns
NA

Example Code
Example: SimpleServerWiFi
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleServerWiFi/SimpleServerWiFi.ino)

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::available

Description
Gets a client that is connected to the server and has data available for reading. The connection persists when the returned client object goes out of scope; you can close it by calling the client.stop().

Syntax
WiFiClient available(uint8_t* status = NULL);

Parameters
status: Wi-Fi availability status. Default value: NULL.

Returns
This function returns a client object; if no Client has data available for reading, this object will evaluate to false in an if-statement.

Example Code
Example: SimpleServerWiFi
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleServerWiFi/SimpleServerWiFi.ino)

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::begin

Description
Server start listening for incoming connections.

Syntax
void begin(void);

Parameters
NA

Returns
NA

Example Code
Example: SimpleServerWiFi
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleServerWiFi/SimpleServerWiFi.ino)

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::connected

Description
Check if server is still connected.

Syntax
uint8_t connected(void);

Parameters
NA

Returns
This function returns ‘1’ if connected, returns ‘0’ if not connected.

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::close

Description
Disconnect the server.

Syntax
void close(void);

Parameters
NA

Returns
NA

Example Code
Example: SimpleServerWiFi
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleServerWiFi/SimpleServerWiFi.ino)

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::end

Description
Disconnect the server.

Syntax
void end(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::recv

Description
Read the received byte from the server.

Syntax
int recv(uint8_t* buf, size_t size);

Parameters
buf: buffer to hold received byte
size: maximum size of the buffer

Returns
This function returns 1 and number of bytes received or returns -1 if no data is available.

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::setTimeout

Description
Set the amount of time the server can take to send data to the client.

Syntax
void setTimeout(int timeout);

Parameters
timeout: timeout in seconds

Returns
This function returns “0” if server is not connected.

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::stop

Description
Stop socket connection for server driver.

Syntax
virtual void stop(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::write

Description
Write data to all the clients connected to a server.

Syntax
virtual size_t write(uint8_t b);
virtual size_t write(const uint8_t *buf, size_t size);

Parameters
b: byte to be written
buf: data buffer
size: size of the data buffer

Returns
This function returns the number of bytes written. It is not necessary to read this.

Example Code
Example: SimpleServerWiFi
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleServerWiFi/SimpleServerWiFi.ino)

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::enableIPv6

Description
Enable IPv6 usage.

Syntax
int enableIPv6(void);

Parameters
NA

Returns
This function return ‘1’ when IPv6 is enabled.

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

WiFiServer::getIPv6Status

Description
Return current IPv6 enabled status.

Syntax
int getIPv6Status(void);

Parameters
NA

Returns
This function returns current IPv6 enabled status. “1” indicating IPv6 is enabled.

Example Code
NA

Notes and Warnings
“WiFiServer.h” must be included to use the class function.

请先确认已安装QQ通讯软体