Home  +  Forums  +  C++ and Sockets  +  C++ and SQL: MySQL, sqlite, ODBC  +  Miscellaneous Projects
Logo
~Sockets~
~New~
~Examples~
~Contact~

C++ Socket library tutorial

An SSL client that talks to the ssl statusserver

Prev   |   Menu   |   Next

This client code will talk to the statusserver presented on the previous page. If port 2222 is used, ssl will be enabled.

sslclient.cpp
#include <SocketHandler.h>
#include <TcpSocket.h>


class MyClient : public TcpSocket
{
public:
	MyClient(ISocketHandler& h) : TcpSocket(h) {
		SetLineProtocol();
	}

	void OnConnect() {
		printf("Connected\n");
	}

	void InitSSLClient() {
		TcpSocket::InitSSLClient();
		printf("SSL client init in progress\n");
	}

	void OnLine(const std::string& line) {
		printf("%s\n", line.c_str());
	}

};


int main(int argc,char *argv[])
{
	if (argc != 3)
	{
		fprintf(stderr, "Usage: %s <-hostname> <-port>\n", *argv);
		exit(-1);
	}
	SocketHandler h;
	MyClient sock(h);
	port_t port = atoi(argv[2]);
	if (port == 2222)
	{
		sock.EnableSSL();
	}
	sock.Open(argv[1], port);
	h.Add(&sock);
	while (h.GetCount())
	{
		h.Select();
	}
}

Prev   |   Menu   |   Next

Valid HTML 4.01!

Validate
Page, code, and content Copyright (C) 2021 by Anders Hedström