Server¶
Server that stands between a client and Cadence Virtuoso.
-
class
socad.server.Server(cad_stream, sock=None)¶ A server that handles skill commands.
This server is started and ran by Cadence Virtuoso. It receives data from a client and passes it to Cadence. It then gather the Cadence response and send it back to the client. The data sent to client is serialized in JSON and the data from client should also be in JSON.
Parameters: -
close(code)¶ Close the server socket and end the communication with Cadence.
Parameters: code (int) – exit code.
-
recv_bytes(n_bytes)¶ Receive a specified number of bytes through a socket.
Parameters: n_bytes (int) – number of bytes to receive. Raises: ConnectionError– if the socket connection is broken.Returns: received bytes stream. Return type: bytes
-
recv_data()¶ Receive an object through a socket.
1 - Receive the first 4 bytes of data, which contains the data length;
2 - Receive the data, serialized in JSON, and decode it;
3 - Convert the received data in an object.
Raises: ConnectionError– if the socket connection is broken.TypeError– if the received data is not in JSON format.
Returns: decoded and de-serialized received data.
Return type:
-
recv_skill()¶ Receive a response from Cadence.
First receives the message length (number of bytes) and then receives the message.
Returns: message received from Cadence Virtuoso. Return type: str
-
run(host, port)¶ Start the server.
Parameters: Raises: ConnectionError– if there’s a communication problem.Returns: remote socket name.
Return type:
-
send_data(obj)¶ Send an object through a socket.
1 - Serialize the object in JSON and encode the string;
- 2 - pack the serialized object length in an unsigned int (I) [4 bytes],
- and big-endian byte order (>) (this way the object size message has always the same size);
3 - send the data.
Parameters: obj (dict) – object to send.
Raises: TypeError– if the object is not serializable in JSON.ConnectionError– if the socket connection is broken.
-