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

C++ Socket library tutorial

Creating a socket that returns SocketHandler status

Prev   |   Menu   |   Next

This specialization of the TcpSocket class will return a few lines with information from the SocketHandler class, and then stay there. It is written to be used as a server socket; only the OnAccept() method is implemented, and OnAccept() is called by the SocketHandler when an incoming connection is established.

This class will be reused in a later example, with a custom SocketHandler.

StatusSocket.h
#ifndef _STATUSSOCKET_H
#define _STATUSSOCKET_H

#include <TcpSocket.h>
#include <ISocketHandler.h>


class StatusSocket : public TcpSocket
{
public:
	StatusSocket(ISocketHandler& );

	void OnAccept();

};


#endif // _STATUSSOCKET_H

Some text about.

StatusSocket.cpp
#include <Utility.h>
#include "StatusSocket.h"


StatusSocket::StatusSocket(ISocketHandler& h)
:TcpSocket(h)
{
}


void StatusSocket::OnAccept()
{
	Send("Local hostname : " + Utility::GetLocalHostname() + "\n");
	Send("Local address : " + Utility::GetLocalAddress() + "\n");
	Send("Number of sockets in list : " + Utility::l2string(Handler().GetCount()) + "\n");
	Send("\n");
}



Prev   |   Menu   |   Next

Valid HTML 4.01!

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