> 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/client/network/network.md).

# Network

This class receive all the packets from the server and add them in a queue

## Public member functions

<pre class="language-cpp"><code class="lang-cpp">Network(std::string ip = "127.0.0.1", int port = 4242);
~Network();
void setInst(unsigned char inst);
<strong>Stream &#x26;getStreamOut();
</strong>void send(const Stream &#x26;stream);
void send();
void read();
<strong>void startReceive();
</strong>Queue&#x3C;Network::Packet> &#x26;getQueueIn();
std::pair&#x3C;size_t, Stream> getNextInst();
void setClosed(bool closed);
</code></pre>

## Public attributes

```cpp
std::thread _ReaderThread;
```

## Private attributes

```cpp
std::string _ip;
int _port;
asio::io_context _ioContext;
asio::ip::udp::socket _socket;
asio::ip::udp::endpoint _serverEndpoint;
bool _closed;
Stream _streamOut;
unsigned char _instOut;
Stream _streamIn;
Queue<Network::Packet> _queueIn;
```

## Member functions documentation

### Constructor

```cpp
Network(std::string ip = "127.0.0.1", int port = 4242);
```

#### Parameters

* `ip:` The client ip
* `port:` The server port

### setInst

Set the \_instOut attribute

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

### getStreamOut

return the \_outStream attribute

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

### 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();
```

### read

This method start the clock that read inputs

```cpp
void read();
```

### startReceive

This method is the clock that read inputs

<pre class="language-cpp"><code class="lang-cpp"><strong>void startReceive();
</strong></code></pre>

### getQueueIn

This method return the in packet queue

```cpp
Queue<Network::Packet> &getQueueIn();
```

### getNextInst

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

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

### setClosed

Set the attribute \_closed

```cpp
void setClosed(bool closed);
```
