Simple Socket

Simple Socket

  • Intro
  • Getting Started
  • API
  • GitHub
  • Help

›API

Overview

  • Introduction
  • Building and Installation
  • Getting Started

Examples

  • Application Specific Examples

API

  • CSimpleSocket

CSimpleSocket

Provides a platform independent class to for socket development. This class is designed to abstract socket communication development in a platform independent manner. Socket types:

  • CActiveSocket Class
  • CPassiveSocket Class

Table of Contents

  • Enums
    • CShutdownMode
    • CSocketType
    • CSocketError
  • Functions
    • Get Data
    • Get Client Address
    • Get Server Address
    • Get Joined Group

Enums

CShutdownMode

Defines the three possible states for shuting down a socket.

ModeDescription
ReceivesShutdown Rx socket.
SendsShutdown Tx socket.
BothShutdown both active and passive sockets.

CSocketType

Defines the socket types recognized by CSimpleSocket class.

TypeDescriptionNotes
SocketTypeInvalidInvalid socket type.-
SocketTypeTcpDefines socket as TCP socket.-
SocketTypeUdpDefines socket as UDP socket.-
SocketTypeTcp6Defines socket as IPv6 TCP socket.Not Supported
SocketTypeUdp6Defines socket as IPv6 UDP socket.Not Supported
SocketTypeRawProvides raw network protocol access.Linux Only

CSocketError

Defines all error codes handled by the CSimpleSocket class.

ErrorDescription
SocketErrorGeneric socket error translates to error below.
SocketSuccessNo socket error.
SocketInvalidSocketInvalid socket handle.
SocketInvalidAddressInvalid destination address specified.
SocketInvalidPortInvalid destination port specified.
SocketConnectionRefusedNo server is listening at remote address.
SocketTimedoutTimed out while attempting operation.
SocketEwouldblockOperation would block if socket were blocking.
SocketNotconnectedCurrently not connected.
SocketEinprogressSocket is non-blocking and the connection cannot be completed immediately
SocketInterruptedCall was interrupted by a signal that was caught before a valid connection arrived.
SocketConnectionAbortedThe connection has been aborted.
SocketProtocolErrorInvalid protocol for operation.
SocketFirewallErrorFirewall rules forbid connection.
SocketInvalidSocketBufferThe receive buffer point outside the process's address space.
SocketConnectionResetConnection was forcibly closed by the remote host.
SocketAddressInUseAddress already in use.
SocketInvalidPointerPointer type supplied as argument is invalid.
SocketEunknownUnknown error please report to prince.chrismc@gmail.com

Functions

Get Data

/// Get a pointer to internal receive buffer.  The user MUST not free this
/// pointer when finished.  This memory is managed internally by the CSocket
/// class.
/// @return copy of data if valid, else returns empty.
str::string GetData();

Receive

The internal buffer is only valid until the next call to Receive(), a call to Close(), or until the object goes out of scope.

/// Attempts to receive a block of data on an established connection.
/// @param nMaxBytes maximum number of bytes to receive.
/// @param pBuffer, memory where to receive the data,
///        - NULL receives to internal buffer returned with GetData()
///        - Non-NULL receives directly there, but GetData() will return empty!
/// @return number of bytes actually received.
/// @return of zero means the connection has been shutdown on the other side.
/// @return of -1 means that an error has occurred.
virtual int32 Receive(uint32 nMaxBytes = 1, uint8 * pBuffer = nullptr);

Get Client Address

 /// Returns clients Internet host address as a string in standard numbers-and-dots notation.
 ///  @return IP address or empty if invalid
std::string GetClientAddr();

Get Server Address

/// Returns server Internet host address as a string in standard numbers-and-dots notation.
///  @return IP address or empty if invalid
std::string GetServerAddr();

Get Joined Group

/// Returns the multi-cast group's address as a string in standard numbers-and-dots notation.
///  @return IP address or empty if invalid
std::string GetJoinedGroup();
← Previous
  • Enums
    • CShutdownMode
    • CSocketType
    • CSocketError
  • Functions
    • Get Data
    • Receive
    • Get Client Address
    • Get Server Address
    • Get Joined Group
Simple Socket
Docs
OverviewGetting StartedAPI Reference
Community
Stack Overflow
More
BlogGitHubStar
Facebook Open Source
Copyright © 2018 Christopher McArthur