Skip to main content
Skip table of contents

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 NameData TypeDefault ValueDescription

sock

socket.socket

-

Socket instance returned from server_socket_open()

socket instance

Return

ValueDescription

1

Socket normal state

0

Socket abnormal state

Exception

ExceptionDescription

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

Example 1

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

server_socket_close(sock)

Example 2

PY
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)
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.