# NetworkClientSocket Class Reference

Base socket handler for all TCP sockets. More...

`#include <tcp_game.h>`

Inheritance diagram for NetworkClientSocket:

## Public Member Functions
NetworkRecvStatus | CloseConnection (bool error=true)
| Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit A socket can make errors.
| NetworkClientSocket (ClientID client_id=INVALID_CLIENT_ID)
void | SetInfo (NetworkClientInfo *info)
NetworkClientInfo * | GetInfo () const
const char * | Recv_Command (Packet *p, CommandPacket *cp)
| Receives a command from the network.
void | Send_Command (Packet *p, const CommandPacket *cp)
| Sends a command over the network.
## Data Fields
ClientID | client_id
| Client identifier.
uint32 | last_frame
| Last frame we have executed.
uint32 | last_frame_server
| Last frame the server has executed.
byte | lag_test
| Byte used for lag-testing the client.
ClientStatus | status
| Status of this client.
CommandPacket * | command_queue
| The command-queue awaiting delivery.
## Private Attributes
NetworkClientInfo * | info
| Client info related to this socket.

## Detailed Description

Base socket handler for all TCP sockets.

Definition at line 97 of file tcp_game.h.

## Member Function Documentation

NetworkRecvStatus NetworkClientSocket::CloseConnection | ( | bool | error = `true` | ) | `[virtual]`

Functions to help NetworkRecv_Packet/NetworkSend_Packet a bit A socket can make errors.

When that happens this handles what to do. For clients: close connection and drop back to main-menu For servers: close connection and that is it

Returns:
  the new status TODO: needs to be splitted when using client and server socket packets

Reimplemented from NetworkTCPSocketHandler.

Definition at line 58 of file tcp_game.cpp.

References _network_server, _networking, _switch_mode, NETWORK_RECV_STATUS_CONN_LOST, and NETWORK_RECV_STATUS_SERVER_ERROR.

const char * NetworkClientSocket::Recv_Command | ( | Packet * | p,
|  | CommandPacket * | cp |
| ) |  |  |

Receives a command from the network.

Parameters:

  | p | the packet to read from.
  | cp | the struct to write the data to.

Returns:
  an error message. When NULL there has been no error.

Definition at line 197 of file network_command.cpp.

References _callback_table, CommandContainer::callback, CommandContainer::cmd, CMD_FLAGS_MASK, CMD_OFFLINE, CommandPacket::company, GetCommandFlags(), IsValidCommand(), lengthof, CommandContainer::p1, CommandContainer::p2, Packet::Recv_string(), CommandContainer::text, and CommandContainer::tile.

Referenced by DEF_SERVER_RECEIVE_COMMAND().

void NetworkClientSocket::Send_Command | ( | Packet * | p,
|  | const CommandPacket * | cp |
| ) |  |  |

Sends a command over the network.

Parameters:

  | p | the packet to send it in.
  | cp | the packet to actually send.

Definition at line 222 of file network_command.cpp.

References _callback_table, CommandContainer::callback, CommandContainer::cmd, CommandPacket::company, lengthof, CommandContainer::p1, CommandContainer::p2, Packet::Send_string(), CommandContainer::text, and CommandContainer::tile.

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

- src/network/core/tcp_game.h
- src/network/core/tcp_game.cpp
- src/network/network_command.cpp