WiFiServer Class
WiFiServer Class
Description
A class of WiFi server implementation for Ameba.
Syntax
class WiFiServer
Members
Public Constructors | |
WiFiServer::WiFiServer | Constructs a WiFiServer object and creates a server that listens for incoming connections on the specified port. |
Public Methods | |
WiFiServer::available | Gets a client that is connected to the server and has data available for reading. |
WiFiServer::begin | Server start listening for incoming connections. |
WiFiServer::connected | Check if Server is still connected. |
WiFiServer::close | Disconnect the server. |
WiFiServer::end | Disconnect the server. |
WiFiServer::recv | Read the received byte from the server. |
WiFiServer::setTimeout | Set the amount of time the server can take to send data to the client. |
WiFiServer::stop | Disconnect the server. |
WiFiServer::write | Write data to all the clients connected to a server. |
WiFiServer::enableIPv6 | Enable IPv6 Usage. |
WiFiServer::getIPv6Status | Return 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.