Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SimpleSocketExamples 1.0
ClientSocket Class Reference
client socket class for communication endpoint More...
#include <SimpleSocket.h>
| Public Member Functions | |
| ClientSocket (IpAddr ip, int port, float timeout=60, bool debug=false) | |
| creates a ClientSocket object. | |
| ClientSocket (char *hostname, int port, float timeout=60, bool debug=false) | |
| creates a ClientSocket object. | |
| ClientSocket (const ClientSocket &that) | |
| copy constructor | |
| IpAddr | getIp () | 
| gets the IP address. | |
| bool | connected () | 
| gets the connection status. | |
| bool | available () | 
| tests if input data available or not. | |
| int | read () | 
| reads a char. | |
| int | read (char *buf, int size) | 
| reads data into the specified buffer. | |
| int | scanf (const char *format,...) | 
| scans input stream according to the specified format string. | |
| int | write (char c) | 
| writes a char to the output stream. | |
| int | write (char *buf, int size) | 
| writes an array of chars to the output stream. | |
| int | printf (const char *format,...) | 
| prints the data to the socket output stream according to the specified format string. | |
| void | close () | 
| closes the connection. | |
| void | setDebug (bool debug) | 
| sets debug mode. | |
| operator bool () | |
| an operator shorthand for connected() | |
| Friends | |
| class | ServerSocket | 
Detailed Description
client socket class for communication endpoint
Definition at line 159 of file SimpleSocket.h.
Constructor & Destructor Documentation
| ClientSocket | ( | IpAddr | ip, | 
| int | port, | ||
| float | timeout = 60, | ||
| bool | debug = false | ||
| ) | 
creates a ClientSocket object.
- Parameters:
- 
  ip IP address of the socket port port number of the socket timeout max waiting time until connected debug set true to display debugging information 
Definition at line 33 of file ClientSocket.cpp.
| ClientSocket | ( | char * | hostname, | 
| int | port, | ||
| float | timeout = 60, | ||
| bool | debug = false | ||
| ) | 
creates a ClientSocket object.
- Parameters:
- 
  hostname domain/host name of the socket port port number of the socket timeout max waiting time until connected debug set true to display debugging information 
Definition at line 38 of file ClientSocket.cpp.
| ClientSocket | ( | const ClientSocket & | that ) | 
copy constructor
Definition at line 44 of file ClientSocket.cpp.
Member Function Documentation
| bool available | ( | ) | 
tests if input data available or not.
- Returns:
- true if incomming data available, false otherwise
Definition at line 89 of file ClientSocket.cpp.
| void close | ( | ) | 
closes the connection.
Definition at line 211 of file ClientSocket.cpp.
| bool connected | ( | ) | 
gets the connection status.
- Returns:
- true if connected, false otherwise
Definition at line 79 of file ClientSocket.cpp.
| IpAddr getIp | ( | ) | 
gets the IP address.
- Returns:
- IP address of the socket
Definition at line 75 of file ClientSocket.cpp.
| operator bool | ( | ) | 
an operator shorthand for connected()
Definition at line 222 of file ClientSocket.cpp.
| int printf | ( | const char * | format, | 
| ... | |||
| ) | 
prints the data to the socket output stream according to the specified format string.
- Parameters:
- 
  format printf format string, corresponding arguments follow 
- Returns:
- number of chars written, or -1 if failed
Definition at line 201 of file ClientSocket.cpp.
| int read | ( | ) | 
reads a char.
- Returns:
- a char from the socket input stream, or -1 if no data available
Definition at line 131 of file ClientSocket.cpp.
| int read | ( | char * | buf, | 
| int | size | ||
| ) | 
reads data into the specified buffer.
- Parameters:
- 
  buf input buffer size size of the buffer 
- Returns:
- the size of the data read
Definition at line 149 of file ClientSocket.cpp.
| int scanf | ( | const char * | format, | 
| ... | |||
| ) | 
scans input stream according to the specified format string.
format scanf format string, corresponding arguments follow
- Returns:
- number of input items assigned
Definition at line 172 of file ClientSocket.cpp.
| void setDebug | ( | bool | debug ) | 
sets debug mode.
- Parameters:
- 
  debug true to display debugging information 
Definition at line 226 of file ClientSocket.cpp.
| int write | ( | char | c ) | 
writes a char to the output stream.
- Parameters:
- 
  c a char to be written to the socket output stream 
- Returns:
- positive int if succeeded, or -1 if failed
Definition at line 187 of file ClientSocket.cpp.
| int write | ( | char * | buf, | 
| int | size | ||
| ) | 
writes an array of chars to the output stream.
- Parameters:
- 
  buf an array of chars to be written to the socket output stream size number of chars in the array 
- Returns:
- number of chars written, or -1 if failed
Definition at line 191 of file ClientSocket.cpp.
Generated on Sat Jul 23 2022 06:16:20 by
 1.7.2
 1.7.2