server.h File Reference

Library for opening a TCP server, receiving data and sending message to monitor. More...

`#include "image.h"`
Include dependency graph for server.h:

Go to the source code of this file.

## Macros

#define | DEFAULT_SERVER_PORT 2323

## Functions

int | openServer (int port)
| Open server port, connect and listen to given port. More...
int | closeServer ()
| Close server. More...
int | acceptClient ()
| Wait for a client to connect. More...
int | sendDataToServer (char *data, int length)
| Send given data to monitor. More...
int | sendDataToServerForClient (int client, char *data, int length)
| Send given data to monitor, using specific client ID. More...
int | receiveDataFromServer (char *data, int size)
| Read data from monitor. More...
int | receiveDataFromServerFromClient (int client, char *data, int size)
| Read data from monitor, using specific client ID. More...
int | sendImage (Jpg *image)
| Send image to monitor using default client ID. More...

## Detailed Description

Library for opening a TCP server, receiving data and sending message to monitor.

Author
  PE.Hladik

Version
  1.0

Date
  06/06/2017

Definition in file server.h.

## Macro Definition Documentation

## DEFAULT_SERVER_PORT

#define DEFAULT_SERVER_PORT 2323

Definition at line 30 of file server.h.

## Function Documentation

## acceptClient()

int acceptClient | ( |  | ) |

Wait for a client to connect.

Returns
  Return client Id or -1 if it failed

## closeServer()

int closeServer | ( |  | ) |

Close server.

Returns
  -1 if closing failed , 0 otherwise

## openServer()

int openServer | ( | int | port | ) |

Open server port, connect and listen to given port.

Parameters

  port | A valid port number (1024 - 65535)

Returns
  -1 if opening failed or the socket number

## receiveDataFromServer()

int receiveDataFromServer | ( | char * | data,
|  | int | size
| ) |  |

Read data from monitor.

Read, at most, size data from monitor. Data must be a valid pointer to a buffer large enough.

Parameters

  data | A valid pointer to a buffer
  size | Amount of data to read

Returns
  Return amount of data really received. 0 if communication is broken

## receiveDataFromServerFromClient()

int receiveDataFromServerFromClient | ( | int | client,
|  | char * | data,
|  | int | size
| ) |  |

Read data from monitor, using specific client ID.

Read, at most, size data from monitor. Data must be a valid pointer to a buffer large enough.

Parameters

  client | Client Id to receive from
  data | A valid pointer to a buffer
  size | Amount of data to read

Returns
  Return amount of data really received. 0 if communication is broken

## sendDataToServer()

int sendDataToServer | ( | char * | data,
|  | int | length
| ) |  |

Send given data to monitor.

Send given data to monitor using default client ID

Parameters

  data | A valid pointer to a buffer
  length | Amount of data to send

Returns
  Return amount of data really written. 0 if communication is broken

## sendDataToServerForClient()

int sendDataToServerForClient | ( | int | client,
|  | char * | data,
|  | int | length
| ) |  |

Send given data to monitor, using specific client ID.

Send given data to monitor using given client ID.

Parameters

  client | Client Id to send data to
  data | A valid pointer to a buffer
  length | Amount of data to send

Returns
  Return amount of data really written. 0 if communication is broken

## sendImage()

int sendImage | ( | Jpg * | image | ) |

Send image to monitor using default client ID.

Convert image to raw data, and add correct header before sending to monitor

Parameters

  image | An image object after compression

Returns
  Return amount of data really received. 0 if communication is broken