Skip to content

raihahahan/cpp-tcp-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C++ TCP Client with SSL wrapper using OpenSSL

1. Demo

The demo program is to retrieve my public IP address, but this can be used for any TCP request over SSL

Go to demo

2. Installation

  • Note: this has only been tested on Mac M2
make all
./client

3. Explanation

1) Project structure (made with https://marketplace.visualstudio.com/items?itemName=jmkrivocapich.drawfolderstructure)

└── 📁cpp-tcp-client
    └── 📁include
        ├── http_client.h
        ├── tcp_socket.h
        ├── tls_client.h
    └── 📁src
        ├── http_client.cpp
        ├── main.cpp
        ├── tcp_socket.cpp
        ├── tls_client.cpp
    ├── Makefile

2) How it works

  1. Resolve host: get IP from hostname (gethostbyname)
  2. Open TCP socket: socket() + connect() to server:443
  3. Start TLS: wrap socket with OpenSSL (SSL_connect)
  4. Send HTTP request: SSL_write("GET ...")
  5. Receive response: SSL_read() until done
  6. Parse body: extract the data
  7. Cleanup: shutdown TLS, free SSL, close socket

4. References

About

Simple C++ TCP Client with SSL wrapper using OpenSSL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published