> For the complete documentation index, see [llms.txt](https://redboard.gitbook.io/r-type-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://redboard.gitbook.io/r-type-1/server/network/client.md).

# Client

The Client class store all networking information about a client

## Public member functions

```cpp
//Construct a new client
Client(asio::ip::udp::socket &socket, asio::ip::udp::endpoint endpoint);
//Destruct a client
~Client();
Client(const Client &client) = delete;
Client(Client &&client) = delete;
Client &operator=(const Client &client) = delete;
Client &operator=(Client &&client) = delete;
//get the client endpoint
const asio::ip::udp::endpoint &getEndpoint() const;
//get all the incomming client data before being packaged
Stream &getStreamIn();
//return an instruction and a stream if a package is avaible in _streamIn
std::pair<size_t, Stream> getNextInst();
//get the out binary buffer in preparation
Stream &getStreamOut();
//set an instruction before sending
void setInst(unsigned char inst);
//send a Stream to this client
void send(const Stream &message);
//send the Stream _streamOut with the _instOut
void send();
//check last time client exchange with the server
bool isAlive();
//update the client activity
void ping();
```

## Private attributes

```cpp
asio::ip::udp::socket &_socket;
asio::ip::udp::endpoint _endpoint;
Stream _streamIn;
Stream _streamOut;
unsigned char _instOut;
size_t _lastActivity;
std::chrono::system_clock::time_point _lastPing = std::chrono::system_clock::now();
```

## Member functions documentation

### Constructor

```cpp
Client(asio::ip::udp::socket &socket, asio::ip::udp::endpoint endpoint);
```

#### Parameters

* `socket` the server socket
* `endpoint` the client endpoint

### getEndpoint

return the client endpoint

```cpp
const asio::ip::udp::endpoint &getEndpoint() const;
```

### getStreamIn

return the incomming stream

```cpp
Stream &getStreamIn();
```

### getNextInst

Try to get an instruction from th \_streamIn. If it can, it return the instruction and the stream of request.<br>

```cpp
std::pair<size_t, Stream> getNextInst();
```

### getStreamOut

return the \_outStream attribute

```
Stream &getStreamOut();
```

### setInst

Set the \_instOut attribute

```cpp
void setInst(unsigned char inst);
```

### send

send the Stream in parameter to the client

```cpp
void send(const Stream &message);
```

### send

send the \_streamOut stream with the \_instOut instruction

```cpp
void send();
```

### isAlive

check the time since the last client activity

```cpp
bool isAlive();
```

### ping

refresh th client activity

```cpp
void ping();
```
