Objective Systems, Inc.  
Home
About ASN.1
Products
Free Software
Documents
Services
Resources
Resellers
Customers
Careers
About Us
Contact Us
 

Google


Objective Systems, Inc.

OSSocketClass Class Reference
[TCP/IP or UDP Socket Classes]

Wrapper class for TCP/IP or UDP sockets. More...

#include <rtxCppSocket.h>

List of all members.

Public Member Functions

 OSSocketClass ()
 This is the default constructor.
 OSSocketClass (OSRTSOCKET socket, OSBOOL ownership=FALSE)
 This constructor initializes an instance by using an existing socket.
 OSSocketClass (const OSSocketClass &socket)
 The copy constructor.
 ~OSSocketClass ()
 The destructor.
OSSocketClassaccept (OSIPADDR *destIP=0, int *port=0)
 This method permits an incoming connection attempt on a socket.
int bind (OSIPADDR addr, int port)
 This method associates a local address with a socket.
int bind (const char *pAddrStr, int port)
 This method associates a local address with a socket.
int bind (int port)
 This method associates only a local port with a socket.
int close ()
 This method closes this socket.
int connect (const char *host, int port)
 This method establishes a connection to this socket.
int getStatus ()
 Returns a completion status of last operation.
OSRTSOCKET getSocket () const
 This method returns the handle of the socket.
int listen (int maxConnections)
 This method places a socket into a state where it is listening for an incoming connection.
int recv (OSOCTET *pbuf, int bufsize)
 This method receives data from a connected socket.
int send (const OSOCTET *pdata, int size)
 This method sends data on a connected socket.

Static Public Member Functions

static const char * addrToString (OSIPADDR ipAddr, char *pAddrStr, int bufsize)
 This method converts an IP address to its string representation.
static int stringToAddr (const char *pAddrStr, OSIPADDR &ipAddr)
 This method converts a string containing an Internet Protocol dotted address into a proper OSIPADDR address.

Protected Member Functions

OSBOOL isInitialized ()
int initStatus ()

Protected Attributes

OSRTSOCKET mSocket
 handle of the socket
OSBOOL mOwner
 indicates this class owns the socket


Detailed Description

Wrapper class for TCP/IP or UDP sockets.

Definition at line 45 of file rtxCppSocket.h.


Constructor & Destructor Documentation

OSSocketClass::OSSocketClass  ) 
 

This is the default constructor.

It initializes all internal members with default values and creates a new socket structure.

OSSocketClass::OSSocketClass OSRTSOCKET  socket,
OSBOOL  ownership = FALSE
 

This constructor initializes an instance by using an existing socket.

Parameters:
socket An existing socket handle.
ownership Boolean flag that specifies who is the owner of the socket. If it is TRUE then the socket will be destroyed in the destructor. Otherwise, the user is responsible to close and destroy the socket.

OSSocketClass::OSSocketClass const OSSocketClass socket  ) 
 

The copy constructor.

The copied instance will have the same socket handle as the original one, but will not be the owner of the handle.

OSSocketClass::~OSSocketClass  ) 
 

The destructor.

This closes socket if the instance is the owner of the socket.


Member Function Documentation

OSSocketClass* OSSocketClass::accept OSIPADDR *  destIP = 0,
int *  port = 0
 

This method permits an incoming connection attempt on a socket.

It extracts the first connection on the queue of pending connections on the socket. It then creates a new socket and returns an instance of the new socket. The newly created socket will handle the actual connection and has the same properties as the original socket.

Parameters:
destIP Optional pointer to a buffer that receives the IP address of the connecting entity. It may be NULL.
port Optional pointer to a buffer that receives the port of the connecting entity. It may be NULL.
Returns:
An instance of the new socket class. NULL, if error occur. Use getStatus method to obtain error code.
See also:
rtxSocketAccept

static const char* OSSocketClass::addrToString OSIPADDR  ipAddr,
char *  pAddrStr,
int  bufsize
[static]
 

This method converts an IP address to its string representation.

Parameters:
ipAddr The IP address to be converted.
pAddrStr Pointer to the buffer to receive a string with the IP address.
bufsize Size of the buffer.
Returns:
Pointer to a string with IP-address. NULL, if error occur.

int OSSocketClass::bind int  port  )  [inline]
 

This method associates only a local port with a socket.

It is used on an unconnected socket before subsequent calls to the OSSocketClass::connect or OSSocketClass::listen methods.

Parameters:
port The local port number to assign to the socket.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketBind

bind()

Definition at line 163 of file rtxCppSocket.h.

int OSSocketClass::bind const char *  pAddrStr,
int  port
 

This method associates a local address with a socket.

It is used on an unconnected socket before subsequent calls to the connect or listen methods.

Parameters:
pAddrStr Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
port The local port number to assign to the socket.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketBind

int OSSocketClass::bind OSIPADDR  addr,
int  port
 

This method associates a local address with a socket.

It is used on an unconnected socket before subsequent calls to the connect or listen methods.

Parameters:
addr The local IP address to assign to the socket.
port The local port number to assign to the socket.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketBind

int OSSocketClass::close  ) 
 

This method closes this socket.

Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketClose

int OSSocketClass::connect const char *  host,
int  port
 

This method establishes a connection to this socket.

It is used to create a connection to the specified destination. When the socket call completes successfully, the socket is ready to send and receive data.

Parameters:
host Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
port The destination port to connect.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketConnect

OSRTSOCKET OSSocketClass::getSocket  )  const [inline]
 

This method returns the handle of the socket.

Returns:
The handle of the socket.

Definition at line 208 of file rtxCppSocket.h.

int OSSocketClass::getStatus  )  [inline]
 

Returns a completion status of last operation.

Returns:
Completion status of last operation:
  • 0 = success,
  • negative return value is error.

Definition at line 201 of file rtxCppSocket.h.

int OSSocketClass::listen int  maxConnections  ) 
 

This method places a socket into a state where it is listening for an incoming connection.

Parameters:
maxConnections Maximum length of the queue of pending connections.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketListen

int OSSocketClass::recv OSOCTET *  pbuf,
int  bufsize
 

This method receives data from a connected socket.

It is used to read incoming data on sockets. The socket must be connected before calling this function.

Parameters:
pbuf Pointer to the buffer for the incoming data.
bufsize Length of the buffer.
Returns:
If no error occurs, returns the number of bytes received. Negative error code if error occured.
See also:
rtxSocketRecv

int OSSocketClass::send const OSOCTET *  pdata,
int  size
 

This method sends data on a connected socket.

It is used to write outgoing data on a connected socket.

Parameters:
pdata Buffer containing the data to be transmitted.
size Length of the data in pdata.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.
See also:
rtxSocketSend

static int OSSocketClass::stringToAddr const char *  pAddrStr,
OSIPADDR &  ipAddr
[static]
 

This method converts a string containing an Internet Protocol dotted address into a proper OSIPADDR address.

Parameters:
pAddrStr Null-terminated character string representing a number expressed in the Internet standard "." (dotted) notation.
ipAddr Reference to OSIPADDR to receive converted IP-address.
Returns:
Completion status of operation:
  • 0 = success,
  • negative return value is error.


The documentation for this class was generated from the following file:

This file was last modified on 8 Jan 2007.
XBinder, Version 1.1.9