Class TcpSocket

Inheritance Relationships

Base Type

Class Documentation

class TcpSocket : public O3DS::Socket

Public Functions

TcpSocket()
TcpSocket(int s)
~TcpSocket()
virtual void CreateSocket() override

Calls socket() - throws SocketException.

void Connect(const char *host, unsigned short port)

open a connection to the host/port

void Connect(sockaddr_in *host, unsigned short port)

open a connection to the host/port

void Disconnect()

shut down a connection

void DisconnectSend()

shut down a connection for sending data

void DisconnectReceive()

shut down a connection for reading data

void Listen(int port, bool nonBlocking, int maxConnections)

Listen for a connection.

Set the socket options for blocking, calles Bind then Listen. If blocking is false, function should return right away Throws a SocketException if Bind or Listen fails

bool Accept(int &s, int timeout = 0)

Accept an incoming connection.

Will poll the listening socket and wait for one second for an incoming connection. The reason for doing this rather than using a blocking socket is on unix, the accept will not unblock when the socket is destoryed, so putting this in a thread and checking the shutdown status is required.

Return values:

true – if a connection was made

void Send(std::vector<char> &data)

Puts data on the wire.

void Send(void *data, int len)

Puts data on the wire.

bool Receive(std::vector<char> &data)

Receive data.

Will keep reading in data till TIMEOUT has been exceeded or connection is closed.

void Receive(void *buf, int len, int *recd)

Receive a specific length of data.

void Receive(void *buf, int len)

Recieve a specific length of data, and keep going till its all read.

bool ReceiveToToken(void *data, int len, const char token, int *bytesRead = NULL)

Receive everything up to a token.

Will keep reading in data till TIMEOUT has been exceed or the token is read