socha.api.networking.network_socket#

Module Contents#

Classes#

NetworkSocket

This class represents a network socket that can be used to connect to a server, send data, and receive data.

class socha.api.networking.network_socket.NetworkSocket(host='localhost', port=13050, timeout=0.1)#

This class represents a network socket that can be used to connect to a server, send data, and receive data.

connect()#

Connects the socket to the specified host and port. Sets the timeout value and sets the ‘connected’ attribute to True.

close()#

Closes the socket and sets the ‘connected’ attribute to False.

send(data: bytes)#

Sends the specified data (in bytes) to the connected server.

receive() bytes | None#

Attempts to receive data from the server. The received data is processed using a regular expression to extract complete messages. If a complete message is found, it is returned as bytes and removed from the buffer. If no complete message is found, None is returned.

If a timeout occurs or a connection reset error is encountered, the socket is closed and None is returned.