Client

class Client(self)

Bases: Network

This class represents a Transmission Control Protocol (TCP) client.

TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer.

Example of client’s code, receiving and sending basic message It corresponds to the client used in the first example of vpServer class’ documentation:

#include <iostream>
#include <visp3/core/vpClient.h>

#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif

int main()
{
  std::string servername = "localhost";
  unsigned int port = 35000;

  vpClient client;
  client.connectToHostname(servername, port);
  //client.connectToIP("127.0.0.1",port);

  int val = 0;

  while(1)
  {
    // Sending the new value to the first client
    if(client.send(&val) != sizeof(int))
      std::cout << "Error while sending" << std::endl;
    else
      std::cout << "Sending : " << val << std::endl;

    // Receiving a value from the first client
    if(client.receive(&val) != sizeof(int))
      std::cout << "Error while receiving" << std::endl;
    else
      std::cout << "Received : " << val << std::endl;
  }

  return 0;
}

Example of client’s code, sending a vpImage on request form. It correspond to the server used in the second example of vpServer class’ documentation.

#include <iostream>
#include <visp3/core/vpClient.h>
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/sensor/vpV4l2Grabber.h>

#include "vpRequestImage.h" //See vpRequest class documentation

int main(int argc, char **argv)
{
#if defined(VISP_HAVE_V4L2)
  std::string servername = "localhost";
  unsigned int port = 35000;

  vpImage<unsigned char> I; // Create a gray level image container

  // Create a grabber based on v4l2 third party lib (for usb cameras under
  // Linux)
  vpV4l2Grabber g;
  g.setScale(1);
  g.setInput(0);
  g.open(I);

  // Create an image viewer
#if defined(VISP_HAVE_X11)
  vpDisplayX d(I, -1, -1, "Camera frame");
#elif defined(VISP_HAVE_GDI) //Win32
  vpDisplayGDI d(I, -1, -1, "Camera frame");
#endif

  vpClient client;
  client.connectToHostname(servername, port);
  //client.connectToIP("127.0.0.1",port);

  vpRequestImage reqImage(&I);

  while(1)
  {
    double t = vpTime::measureTimeMs();
    // Acquire a new image
    g.acquire(I);

    vpDisplay::display(I);
    vpDisplay::flush(I);

    client.sendAndEncodeRequest(reqImage);

    // A click in the viewer to exit
    if ( vpDisplay::getClick(I, false) )
      break;
  }

  return 0;
#endif
}

Note

See vpClient

Note

See vpRequest

Note

See vpNetwork

Methods

__init__

connectToHostname

Connect to the server represented by the given hostname, and at a given port.

connectToIP

Connect to the server represented by the given ip, and at a given port.

deconnect

Deconnect from the server at a specific index.

getNumberOfAttempts

Get the actual number of attempts to connect to the server.

getNumberOfServers

Get the number of server that the client is connected on.

print

Overloaded function.

setNumberOfAttempts

Set the number of attempts to connect to the server.

stop

Stops the server and close the sockets.

Inherited Methods

removeDecodingRequest

Delete a decoding request from the emitter.

getMaxSizeReceivedMessage

Get the maximum size that the emitter can receive (in request mode).

setMaxSizeReceivedMessage

Change the maximum size that the emitter can receive (in request mode).

receiveRequest

Receive requests until there is requests to receive.

getReceptorIndex

Get the receptor index from its name.

getRequestIdFromIndex

Get the Id of the request at the index ind.

sendAndEncodeRequestTo

Send and encode a request to a specific receptor.

sendRequestTo

Send a request to a specific receptor.

receiveAndDecodeRequestOnce

Receives a message once (in the limit of the Maximum message size value).

setTimeoutUSec

Change the time the emitter spend to check if he receives a message from a receptor.

receiveAndDecodeRequestFrom

Receives and decode requests, from a specific emitter, until there is request to receive.

sendRequest

Send a request to the first receptor in the list.

receiveRequestFrom

Receives requests, from a specific emitter, until there is request to receive.

receiveAndDecodeRequestOnceFrom

Receives a message once (in the limit of the Maximum message size value), from a specific emitter.

setTimeoutSec

Change the time the emitter spend to check if he receives a message from a receptor.

receiveRequestOnce

Receives a message once (in the limit of the Maximum message size value).

receiveRequestOnceFrom

Receives a message once (in the limit of the Maximum message size value), from a specific emitter.

sendAndEncodeRequest

Send and encode a request to the first receptor in the list.

setVerbose

Set the verbose mode.

receiveAndDecodeRequest

Receives and decode requests until there is requests to receive.

Operators

__doc__

__init__

__module__

Attributes

__annotations__

__init__(self)
connectToHostname(self, hostname: str, port_serv: int) bool

Connect to the server represented by the given hostname, and at a given port.

Parameters:
hostname: str

Hostname of the server.

port_serv: int

Port used for the connection.

Returns:

True if the connection has been etablished, false otherwise.

connectToIP(self, ip: str, port_serv: int) bool

Connect to the server represented by the given ip, and at a given port.

Parameters:
ip: str

IP of the server.

port_serv: int

Port used for the connection.

Returns:

True if the connection has been etablished, false otherwise.

deconnect(self, index: int = 0) None

Deconnect from the server at a specific index.

Parameters:
index: int = 0

Index of the server.

getMaxSizeReceivedMessage(self) int

Get the maximum size that the emitter can receive (in request mode).

Returns:

Acutal max size value.

getNumberOfAttempts(self) int

Get the actual number of attempts to connect to the server.

Returns:

Actual number of attempts.

getNumberOfServers(self) int

Get the number of server that the client is connected on.

Returns:

Number of servers.

getReceptorIndex(self, name: str) int

Get the receptor index from its name. The name can be either the IP, or its name on the network.

Parameters:
name: str

Name of the receptor.

Returns:

Index of the receptor, or -1 if an error occurs.

getRequestIdFromIndex(self, ind: int) str

Get the Id of the request at the index ind.

Parameters:
ind: int

Index of the request.

Returns:

Id of the request.

print(*args, **kwargs)

Overloaded function.

  1. print(self: visp._visp.core.Client) -> None

Print the servers.

  1. print(self: visp._visp.core.Network, id: str = ) -> None

Print the receptors.

Parameters:
id

Message to display before the receptor’s index.

receiveAndDecodeRequest(self) list[int]

Receives and decode requests until there is requests to receive.

Warning

Requests will be received but not decoded.

Note

See vpNetwork::receive()

Note

See vpNetwork::receiveRequestFrom()

Note

See vpNetwork::receiveRequestOnce()

Note

See vpNetwork::receiveRequestOnceFrom()

Note

See vpNetwork::receiveAndDecodeRequest()

Note

See vpNetwork::receiveAndDecodeRequestFrom()

Note

See vpNetwork::receiveAndDecodeRequestOnce()

Note

See vpNetwork::receiveAndDecodeRequestOnceFrom()

receiveAndDecodeRequestFrom(self, receptorEmitting: int) list[int]

Receives and decode requests, from a specific emitter, until there is request to receive.

Warning

Requests will be received but not decoded.

Note

See vpNetwork::receive()

Note

See vpNetwork::receiveRequest()

Note

See vpNetwork::receiveRequestOnce()

Note

See vpNetwork::receiveRequestOnceFrom()

Note

See vpNetwork::receiveAndDecodeRequest()

Note

See vpNetwork::receiveAndDecodeRequestFrom()

Note

See vpNetwork::receiveAndDecodeRequestOnce()

Note

See vpNetwork::receiveAndDecodeRequestOnceFrom()

Parameters:
receptorEmitting: int

Index of the receptor emitting the message

receiveAndDecodeRequestOnce(self) int

Receives a message once (in the limit of the Maximum message size value). This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request. If it represents an entire request, it decodes the request.

Returns:

The number of bytes received, -1 if an error occurred.

receiveAndDecodeRequestOnceFrom(self, receptorEmitting: int) int

Receives a message once (in the limit of the Maximum message size value), from a specific emitter. This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request. If it represents an entire request, it decodes the request.

Parameters:
receptorEmitting: int

Index of the receptor emitting the message.

Returns:

The number of bytes received, -1 if an error occurred.

receiveRequest(self) list[int]

Receive requests until there is requests to receive.

Warning

Requests will be received but not decoded.

Note

See vpNetwork::receive()

Note

See vpNetwork::receiveRequestFrom()

Note

See vpNetwork::receiveRequestOnce()

Note

See vpNetwork::receiveRequestOnceFrom()

Note

See vpNetwork::receiveAndDecodeRequest()

Note

See vpNetwork::receiveAndDecodeRequestFrom()

Note

See vpNetwork::receiveAndDecodeRequestOnce()

Note

See vpNetwork::receiveAndDecodeRequestOnceFrom()

receiveRequestFrom(self, receptorEmitting: int) list[int]

Receives requests, from a specific emitter, until there is request to receive.

Warning

Requests will be received but not decoded.

Note

See vpNetwork::receive()

Note

See vpNetwork::receiveRequest()

Note

See vpNetwork::receiveRequestOnce()

Note

See vpNetwork::receiveRequestOnceFrom()

Note

See vpNetwork::receiveAndDecodeRequest()

Note

See vpNetwork::receiveAndDecodeRequestFrom()

Note

See vpNetwork::receiveAndDecodeRequestOnce()

Note

See vpNetwork::receiveAndDecodeRequestOnceFrom()

Parameters:
receptorEmitting: int

Index of the receptor emitting the message

receiveRequestOnce(self) int

Receives a message once (in the limit of the Maximum message size value). This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request.

Returns:

The number of bytes received, -1 if an error occurred.

receiveRequestOnceFrom(self, receptorEmitting: int) int

Receives a message once (in the limit of the Maximum message size value), from a specific emitter. This message can represent an entire request or not. Several calls to this function might be necessary to get the entire request.

Parameters:
receptorEmitting: int

Index of the receptor emitting the message.

Returns:

The number of bytes received, -1 if an error occurred.

removeDecodingRequest(self, arg0: str) None

Delete a decoding request from the emitter.

Note

See vpNetwork::addDecodingRequest()

sendAndEncodeRequest(self, req: visp._visp.core.Request) int

Send and encode a request to the first receptor in the list.

Parameters:
req: visp._visp.core.Request

Request to send.

Returns:

The number of bytes that have been sent, -1 if an error occurred.

sendAndEncodeRequestTo(self, req: visp._visp.core.Request, dest: int) int

Send and encode a request to a specific receptor.

Parameters:
req: visp._visp.core.Request

Request to send.

dest: int

Index of the receptor receiving the request.

Returns:

The number of bytes that have been sent, -1 if an error occurred.

sendRequest(self, req: visp._visp.core.Request) int

Send a request to the first receptor in the list.

Parameters:
req: visp._visp.core.Request

Request to send.

Returns:

The number of bytes that have been sent, -1 if an error occurred.

sendRequestTo(self, req: visp._visp.core.Request, dest: int) int

Send a request to a specific receptor.

Parameters:
req: visp._visp.core.Request

Request to send.

dest: int

Index of the receptor receiving the request.

Returns:

The number of bytes that have been sent, -1 if an error occurred.

setMaxSizeReceivedMessage(self, s: int) None

Change the maximum size that the emitter can receive (in request mode).

Note

See vpNetwork::getMaxSizeReceivedMessage()

Parameters:
s: int

new maximum size value.

setNumberOfAttempts(self, nb: int) None

Set the number of attempts to connect to the server.

Note

See vpClient::getNumberOfAttempts()

Parameters:
nb: int

Number of attempts.

setTimeoutSec(self, sec: int) None

Change the time the emitter spend to check if he receives a message from a receptor. Initially this value is set to 10usec.

Note

See vpNetwork::setTimeoutUSec()

Parameters:
sec: int

new value in second.

setTimeoutUSec(self, usec: int) None

Change the time the emitter spend to check if he receives a message from a receptor. Initially this value is set to 10usec.

Note

See vpNetwork::setTimeoutSec()

Parameters:
usec: int

new value in micro second.

setVerbose(self, mode: bool) None

Set the verbose mode.

Parameters:
mode: bool

Change the verbose mode. True to turn on, False to turn off.

stop(self) None

Stops the server and close the sockets.