Server¶
- class Server(*args, **kwargs)¶
Bases:
Network
This class represents a Transmission Control Protocol (TCP) server.
TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer.
Example of server’s code, receiving and sending basic message. It corresponds to the client used in the first example of vpClient class’ documentation.
#include <iostream> #include <visp3/core/vpServer.h> int main(int argc,const char** argv) { int port = 35000; vpServer serv(port); //Launch the server on localhost serv.start(); bool run = true; int val; while(run){ serv.checkForConnections(); if(serv.getNumberOfClients() > 0) { // Receiving a value from the first client if(serv.receive(&val) != sizeof(int)) std::cout << "Error while receiving" << std::endl; else std::cout << "Received : " << val << std::endl; val = val+1; // Sending the new value to the first client if(serv.send(&val) != sizeof(int)) std::cout << "Error while sending" << std::endl; else std::cout << "Sending : " << val << std::endl; } } return 0; }
Example of server’s code, receiving a vpImage on request form. It correspond to the client used in the second example of vpClient class’ documentation.
#include <visp3/core/vpServer.h> #include <visp3/gui/vpDisplayGDI.h> #include <visp3/gui/vpDisplayX.h> #include "vpRequestImage.h" //See vpRequest class documentation int main(int argc,const char** argv) { int port = 35000; std::cout << "Port: " << port << std::endl; vpServer serv(port); serv.start(); #if defined(VISP_HAVE_X11) vpDisplayX display; #elif defined(VISP_HAVE_GDI) //Win32 vpDisplayGDI display; #endif vpImage<unsigned char> I; vpRequestImage reqImage(&I); serv.addDecodingRequest(&reqImage); bool run = true; while(run){ serv.checkForConnections(); if(serv.getNumberOfClients() > 0) { int index = serv.receiveAndDecodeRequestOnce(); std::string id = serv.getRequestIdFromIndex(index); if(id == reqImage.getId()) { #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) if (! display.isInitialised() ) display.init(I, -1, -1, "Remote display"); #endif vpDisplay::display(I) ; vpDisplay::flush(I); // A click in the viewer to exit if ( vpDisplay::getClick(I, false) ) run = false; } } } return 0; }
Note
See vpClient
Note
See vpRequest
Note
See vpNetwork
Overloaded function.
__init__(self: visp._visp.core.Server) -> None
Construct a server on the machine launching it.
__init__(self: visp._visp.core.Server, port: int) -> None
__init__(self: visp._visp.core.Server, adress_serv: str, port_serv: int) -> None
Construct a server on the machine at a given adress, with a specified port.
- Parameters:
- adress_serv
server’s adress.
- port_serv
server’s port.
Methods
Overloaded function.
Check if a client has connected or deconnected the server
Get the maximum number of clients that can be connected to the server.
Get the number of clients connected to the server.
Check if the server is started.
Overloaded function.
Set the maximum number of clients that can be connected to the server.
Enable the server to wait for clients (on the limit of the maximum limit).
Inherited Methods
Delete a decoding request from the emitter.
Send a request to a specific receptor.
Send a request to the first receptor in the list.
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 a message once (in the limit of the Maximum message size value), from a specific emitter.
Send and encode a request to a specific receptor.
Receive requests until there is requests to receive.
Change the maximum size that the emitter can receive (in request mode).
Receives a message once (in the limit of the Maximum message size value).
Set the verbose mode.
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 requests, from a specific emitter, until there is request to receive.
Send and encode a request to the first receptor in the list.
Get the receptor index from its name.
Receives and decode requests until there is requests to receive.
Get the maximum size that the emitter can receive (in request mode).
Get the Id of the request at the index ind.
Receives a message once (in the limit of the Maximum message size value).
Operators
__doc__
Overloaded function.
__module__
Attributes
__annotations__
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.Server) -> None
Construct a server on the machine launching it.
__init__(self: visp._visp.core.Server, port: int) -> None
__init__(self: visp._visp.core.Server, adress_serv: str, port_serv: int) -> None
Construct a server on the machine at a given adress, with a specified port.
- Parameters:
- adress_serv
server’s adress.
- port_serv
server’s port.
- checkForConnections(self) bool ¶
Check if a client has connected or deconnected the server
- Returns:
True if a client connected or deconnected, false otherwise OR server not started yet.
- getMaxNumberOfClients(self) int ¶
Get the maximum number of clients that can be connected to the server.
- Returns:
Maximum number of clients.
- getMaxSizeReceivedMessage(self) int ¶
Get the maximum size that the emitter can receive (in request mode).
- Returns:
Acutal max size value.
- getNumberOfClients(self) int ¶
Get the number of clients connected to the server.
- Returns:
Number of clients connected.
- 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.
- isStarted(self) bool ¶
Check if the server is started.
- Returns:
True if the server is started, false otherwise.
- print(*args, **kwargs)¶
Overloaded function.
print(self: visp._visp.core.Server) -> None
Print the connected clients.
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 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.
- 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 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.
- 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.
- setMaxNumberOfClients(self, l: int) None ¶
Set the maximum number of clients that can be connected to the server.
Note
See vpServer::getMaxNumberOfClients()
- setMaxSizeReceivedMessage(self, s: int) None ¶
Change the maximum size that the emitter can receive (in request mode).
Note
See vpNetwork::getMaxSizeReceivedMessage()
- 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()