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> 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
Connect to the server represented by the given hostname, and at a given port.
Connect to the server represented by the given ip, and at a given port.
Deconnect from the server at a specific index.
Get the actual number of attempts to connect to the server.
Get the number of server that the client is connected on.
Overloaded function.
Set the number of attempts to connect to the server.
Stops the server and close the sockets.
Inherited Methods
Set the verbose mode.
Get the maximum size that the emitter can receive (in request mode).
Change the time the emitter spend to check if he receives a message from a receptor.
Send a request to a specific receptor.
Send and encode a request to a specific receptor.
Change the maximum size that the emitter can receive (in request mode).
Delete a decoding request from the emitter.
Get the receptor index from its name.
Receives a message once (in the limit of the Maximum message size value).
Send a request to the first receptor in the list.
Receives requests, from a specific emitter, until there is request to receive.
Send and encode a request to the first receptor in the list.
Receives a message once (in the limit of the Maximum message size value), from a specific emitter.
Receive requests until there is requests to receive.
Receives a message once (in the limit of the Maximum message size value), from a specific emitter.
Change the time the emitter spend to check if he receives a message from a receptor.
Receives and decode requests, from a specific emitter, until there is request to receive.
Receives and decode requests until there is requests to receive.
Receives a message once (in the limit of the Maximum message size value).
Get the Id of the request at the index ind.
Operators
__doc__
__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.
- connectToIP(self, ip: str, port_serv: int) bool ¶
Connect to the server represented by the given ip, and at a given port.
- 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.
- print(*args, **kwargs)¶
Overloaded function.
print(self: visp._visp.core.Client) -> None
Print the servers.
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()
- 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 occured.
- 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.
- 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()
- 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 occured.
- 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.
- 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 occured.
- 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 occured.
- 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 occured.
- 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 occured.
- setMaxSizeReceivedMessage(self, s: int) None ¶
Change the maximum size that the emitter can receive (in request mode).
Note
See vpNetwork::getMaxSizeReceivedMessage()
- setNumberOfAttempts(self, nb: int) None ¶
Set the number of attempts to connect to the server.
Note
See vpClient::getNumberOfAttempts()
- 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()
- 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()