(2.11.2_temp-en_US) client_socket_state(sock)
Features
This function returns the socket connection status.To know the connection status with the server, check the return value of client_socket_read or client_socket_write (see Example 2).
Parameters
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
sock | socket.socket | - | Socket instance returned from client_socket_open() |
Return
Value | Description |
---|---|
1 | Socket normal state |
0 | Socket abnormal state |
Exception
Exception | Description |
---|---|
DR_Error (DR_ERROR_TYPE) | Parameter data type error occurred |
Example
sock = client_socket_open("192.168.137.200", 20002)
state = client_socket_state(sock) # Reads the socket state.
client_socket_close(sock)
Example 2
sock = client_socket_open("192.168.137.200", 20002)
res, rx_data =client_socket_read(sock)
tp_log("[RX] res={0}, rx_data ={1}".format(res, rx_data))
if (res < 0):
tp_log("[RX] server disconnect") #When the server connection is disconnected
client_socket_close(sock)
exit()
client_socket_close(sock)