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:
  • cad_stream (object) – Cadence stream.
  • sock (object, optional) – socket to use in the connection (default: None).
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:
Returns:

decoded and de-serialized received data.

Return type:

dict

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:
  • host (str) – remote socket IP address.
  • port (int) – remote socket port.
Raises:

ConnectionError – if there’s a communication problem.

Returns:

remote socket name.

Return type:

list

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:
send_debug(msg)

Send a debug message to Cadence Virtuoso.

Parameters:msg (str) – debug message.
send_skill(expr)

Send a skill expression to Cadence Virtuoso for evaluation.

Parameters:data (str) – skill expression.
send_warn(warn)

Send a warning message to Cadence Virtuoso.

Parameters:warn (str) – warning message.