3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.2 3.2.1 3.2.0 Korean English Chinese Czech Dutch French German Hungarian Italian Japanese Polish Portuguese Spanish
3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.2 3.2.1 3.2.0 Korean English Chinese Czech Dutch French German Hungarian Italian Japanese Polish Portuguese Spanish

client_socket_read()

Definition

client_socket_read(sock, length=-1, timeout=-1)

Features

This function receives data from the server.

Parameters

Parameter Name

Data Type

Default Value

Description

sock

socket.socket

-

Socket instance returned from client_socket_open()

length

int

-1

Number of bytes of the received data

  • -1 : Not specified (The number of bytes to read is not specified.)

  • n(>=0) : The specified number of bytes is read.

timeout

int

float

-1

Waiting time for receipt

  • -1 : Indefinite wait

  • n(>0) : n seconds

Return

Value (res, rx_data)

Description

res

>0

Number of bytes of the received data

-1

The server is not connected.

-2

Socket.error occurred during data reception

-3

Timeout during data reception

rx_data

Received data (byte type)

Exception

Exception

Description

DR_Error (DR_ERROR_TYPE)

Parameter data type error occurred

DR_Error (DR_ERROR_VALUE)

Parameter value is invalid

Example

Python
sock = client_socket_open("192.168.137.200", 20002)
 
res, rx_data = client_socket_read(sock)   # Indefinite wait until the data is received 
# Reads all received data since the length is omitted. 
# Waits indefinitely until the data is received since timeout is omitted.
# (res = size of received data, rx_data=received data) is returned when the data is received. 
 
res, rx_data = client_socket_read(sock, timeout=3) # Waits for up to 3 seconds until the data is received.
# (res = size of received data, rx_data=received data) is returned if the data is received within 3 seconds.
# (res = -3, rx_data=None) is returned if the data is not received within 3 seconds. 
 
res, rx_data = client_socket_read(sock, length=64)   # Reads 64 bytes of the received data. 
 
res, rx_data = client_socket_read(sock, length=64, timeout=3)
# Reads 64 bytes of the received data within the 3-second timeout.
 
rx_msg = rx_data.decode() # rx_data is a byte type and can be converted to a string type
                         # using decode().
                         # For example, if rx_data = b"abcd", 
						 # rx_msg= "abcd".
client_socket_close(sock)

Keyword

client / client_ / socket / client_socket / client_socket_