# SocketLayer Class Reference

`#include <SocketLayer.h>`

List of all members.

## Public Member Functions

| SocketLayer ()
| ~SocketLayer ()
SOCKET | Connect (SOCKET writeSocket, unsigned long binaryAddress, unsigned short port)
SOCKET | CreateBoundSocket (unsigned short port, bool blockingSocket)
const char * | DomainNameToIP (const char *domainName)
bool | AssociateSocketWithCompletionPortAndRead (SOCKET readSocket, unsigned long binaryAddress, unsigned short port, RakPeer *rakPeer)
void | Write (SOCKET writeSocket, const char *data, int length)
bool | RecvFrom (SOCKET s, RakPeer *rakPeer, int *errorCode)
void | GetMyIP (char ipList[10][16])
int | SendTo (SOCKET s, char *data, int length, char ip[16], unsigned short port)
int | SendTo (SOCKET s, char *data, int length, unsigned long binaryAddress, unsigned short port)

## Static Public Member Functions

static SocketLayer * | Instance ()

## Static Private Attributes

static bool | socketLayerStarted = false
static SocketLayer | I

## Detailed Description

the SocketLayer provide platform independent Socket implementation

## Constructor & Destructor Documentation

SocketLayer::SocketLayer | ( |  | ) |

| Default Constructor

SocketLayer::~SocketLayer | ( |  | ) |

| Destructor

## Member Function Documentation

bool SocketLayer::AssociateSocketWithCompletionPortAndRead | ( | SOCKET | readSocket,
|  | unsigned long | binaryAddress,
|  | unsigned short | port,
|  | RakPeer * | rakPeer
| ) |

| Start an asynchronous read using the specified socket. The callback will use the specified PlayerID (associated with this socket) and call either the client or the server callback (one or the other should be 0)

SOCKET SocketLayer::Connect | ( | SOCKET | writeSocket,
|  | unsigned long | binaryAddress,
|  | unsigned short | port
| ) |

Create a socket connected to a remote host

Parameters:

  | writeSocket | The local socket
  | binaryAddress | The address of the remote host
  | port | the remote port

Returns:
  A new socket used for communication

Todo:
  Check for the binary address byte order

SOCKET SocketLayer::CreateBoundSocket | ( | unsigned short | port,
|  | bool | blockingSocket
| ) |

Creates a socket to listen for incoming connections on the specified port

Parameters:

  | port | the port number
  | blockingSocket |

Returns:
  A new socket used for accepting clients

const char * SocketLayer::DomainNameToIP | ( | const char * | domainName | ) |

void SocketLayer::GetMyIP | ( | char | ipList[10][16] | ) |

Retrieve all local IP address in a printable format

Parameters:

  | ipList | An array of ip address in dot format.

static SocketLayer* SocketLayer::Instance | ( |  | ) | `[inline, static]`

Get Singleton Instance of the Socket Layer unique object.

Returns:
  unique instance

bool SocketLayer::RecvFrom | ( | SOCKET | s,
|  | RakPeer * | rakPeer,
|  | int * | errorCode
| ) |

Read data from a socket

Parameters:

  | s | the socket
  | rakPeer |
  | errorCode | An error code if an error occured

Returns:
  Returns true if you successfully read data

Todo:
  check the role of RakPeer

int SocketLayer::SendTo | ( | SOCKET | s,
|  | char * | data,
|  | int | length,
|  | unsigned long | binaryAddress,
|  | unsigned short | port
| ) |

Send data to a peer. The socket should not be connected to a remote host.

Parameters:

  | s | the socket
  | data | the byte buffer to send
  | length | The length of the data
  | binaryAddress | The peer address in binary format.
  | port | The port number used by the remote host

Returns:
  0 on success.

Todo:
  check return value

int SocketLayer::SendTo | ( | SOCKET | s,
|  | char * | data,
|  | int | length,
|  | char | ip[16],
|  | unsigned short | port
| ) |

Send data to a peer. The socket should not be connected to a remote host.

Parameters:

  | s | the socket
  | data | the byte buffer to send
  | length | The length of the data
  | ip | The address of the remote host in dot format
  | port | The port number used by the remote host

Returns:
  0 on success.

Todo:
  check return value

void SocketLayer::Write | ( | SOCKET | writeSocket,
|  | const char * | data,
|  | int | length
| ) |

Does a writing operation on a socket. It Send a packet to a peer throught the network. The socket must be connected

Parameters:

  | writeSocket | the socket to use to do the communication
  | data | a byte buffer containing the data
  | length | the size of the byte buffer

## Member Data Documentation

SocketLayer SocketLayer::I`[static, private]`

| Singleton instance

bool SocketLayer::socketLayerStarted = false`[static, private]`

| Tel whether or not the socket layer is already active

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

- Projects/raknet/include/raknet/SocketLayer.h
- Projects/raknet/Source/SocketLayer.cpp