https://github.com/loopj/tcpclient
Arduino-Style POSIX TCP Client
https://github.com/loopj/tcpclient
Last synced: about 1 year ago
JSON representation
Arduino-Style POSIX TCP Client
- Host: GitHub
- URL: https://github.com/loopj/tcpclient
- Owner: loopj
- Created: 2016-02-21T06:36:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-21T06:45:08.000Z (over 10 years ago)
- Last Synced: 2025-04-15T03:55:28.357Z (about 1 year ago)
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Arduino-Style POSIX TCP Client
Arduino's [`EthernetClient`](https://www.arduino.cc/en/Reference/EthernetClient)/[`WiFiClient`](https://www.arduino.cc/en/Reference/WiFiClient) classes and Particle's [`TCPClient`](https://docs.particle.io/reference/firmware/#tcpclient) class make it easy to make network requests from your embedded apps, but in [POSIX](https://en.wikipedia.org/wiki/POSIX) environments (Linux, BSD, Mac) networking can be a little more complicated.
This library provides a `TCPClient` class, which allows you to make TCP requests in a super simple way.
Works great when porting apps or libraries from Arduino or Particle projects to Linux or WiringPi.
## Usage
```c++
// Create a TCP client
TCPClient client;
// Connect to the following address and port
client.connect("httpbin.org", 80);
// Make sure we're connected
if(client.connected()) {
// Make a HTTP GET request
client.println("GET /get HTTP/1.0");
client.println();
// Read the response and print it
while(client.available()) {
printf("%c", client.read());
}
}
// Close the connection
client.stop();
```