---
name: "TCPSession"
section: "3cc"
platform: "linux"
package: "libcommoncpp2-dev"
version: "1.0.13-5"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/TCPSession"
---

# TCPSession(3cc)

The TCP session is used to primarily to represent a client connection that can be managed on a seperate thread. Threaded streamable socket with non-blocking constructor.

## NAME

TCPSession - The TCP session is used to primarily to represent a client connection that can be managed on a seperate thread. Threaded streamable socket with non-blocking constructor.

## SYNOPSIS

`#include <socket.h>`

Inherits **TCPStream**, and **Thread**.

### Public Methods

**TCPSession** (const **InetHostAddress** &host, **tpport\_t** port, int **size**=512, int pri=0, int stack=0)\
 *Create a TCP socket that will be connected to a remote TCP server and that will execute under it's own thread.* **TCPSession** (**TCPSocket** &server, int **size**=512, int pri=0, int stack=0)\
 *Create a TCP socket from a bound TCP server by accepting a pending connection from that server and execute a thread for the accepted connection.*

### Protected Methods

int **waitConnection** (**timeout\_t** **timeout**=TIMEOUT\_INF)\
 *Normally called during the thread Initial() method by default, this will wait for the socket connection to complete when connecting to a remote socket.* **CCXX\_MEMBER** (void) initial(void)\
 *The initial method is used to esablish a connection when delayed completion is used.* **CCXX\_MEMBER** (void) final(void)\
 *TCPSession derived objects can be freely created with 'new' and safely terminate their 'run' method on their own by self-deleting when the thread terminates.*

## DETAILED DESCRIPTION

The TCP session is used to primarily to represent a client connection that can be managed on a seperate thread. Threaded streamable socket with non-blocking constructor.

The TCP session also supports a non-blocking connection scheme which prevents blocking during the constructor and moving the process of completing a connection into the  thread that executes for the session.

**Author:**  David Sugar \<dyfet@ostel.com\>

## CONSTRUCTOR & DESTRUCTOR DOCUMENTATION

### TCPSession::TCPSession (const InetHostAddress & host, tpport\_t port, int size = 512, int pri = 0, int stack = 0)

Create a TCP socket that will be connected to a remote TCP server and that will execute under it's own thread.

**Parameters:**

- *host*

  *internet address of remote TCP server.*

- *port*

  *number of remote server.*

- *size*

  *of streaming buffer.*

- *pri*

  *execution priority relative to parent.*

- *stack*

  *allocation needed on some platforms.*

### TCPSession::TCPSession (TCPSocket & server, int size = 512, int pri = 0, int stack = 0)

*Create a TCP socket from a bound TCP server by accepting a pending connection from that server and execute a thread for the accepted connection.*

**Parameters:**

- *server*

  *tcp socket to accept a connection from.*

- *size*

  *of streaming buffer.*

- *pri*

  *execution priority relative to parent.*

- *stack*

  *allocation needed on some platforms.*

## MEMBER FUNCTION DOCUMENTATION

### TCPSession::CCXX\_MEMBER (void)` [inline, protected]`

*TCPSession derived objects can be freely created with 'new' and safely terminate their 'run' method on their own by self-deleting when the thread terminates.*

**Note:**  *Since a thread cannot delete its own context or join itself, to make a TCPSession that is a self running object that self-deletes, one has to detach the associated thread by using* **detach()** *instead of* **start()***.*

### TCPSession::CCXX\_MEMBER (void)` [protected]`

*The initial method is used to esablish a connection when delayed completion is used.*

*This assures the constructor terminates without having to wait for a connection request to complete.*

### int TCPSession::waitConnection (timeout\_t timeout = TIMEOUT\_INF)` [protected]`

*Normally called during the thread Initial() method by default, this will wait for the socket connection to complete when connecting to a remote socket.*

*One might wish to use* **setCompletion()** *to change the socket back to blocking I/O calls after the connection completes. To implement the session one must create a derived class which implements* **run()***.*

**Returns:**  *0 if successful, -1 if timed out.*

**Parameters:**

- *timeout*

  *to wait for completion in milliseconds.*

## AUTHOR

*Generated automatically by Doxygen for CommonC++ from the source code.*
