Breadcrumbs

server_socket_state()

Definition

server_socket_state(sock)

Features

This function returns the socket status.

To know the connection status with the client, check the return value of server_socket_read or server_socket_write (see Example 2).

Parameters

Parameter Name

Data Type

Default Value

Description

sock

socket.socket

-

Socket instance returned from server_socket_open()

socket instance

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 1

Python
sock = server_socket_open(20002)
 
state = server_socket_state(sock) # Reads the socket state.

server_socket_close(sock)

Example 2

Python
sock = server_socket_open(20002)
 
res, rx_data =server_socket_read(sock)
tp_log("[RX] res={0}, rx_data ={1}".format(res, rx_data)) 
if (res < 0):   #When the client connection is disconnected 
   tp_log("[RX] client disconnect") 
   server_socket_close(sock)             
   exit()
 
server_socket_close(sock)