INNER CODE UNIT · Python
do_receive_from_socket
nordnet/next-api-v2-examples · python3/test_program.py:167
def do_receive_from_socket(socket, last_buffer):
"""
Receive data from the socket, and try to parse it into JSON. Return
the unparsable parts as buffer
"""
# Consume message (price data or heartbeat) from public feed
#> Note that a full message with all the JSON objects ends with a
#> newline symbol "\n". As such you need to listen and read from
#> the buffer until a full message has been transferred
time.sleep(0.01)
new_data = socket.recv(1024).decode('utf-8')
string = last_buffer + new_data
if string != '':
new_buffer = try_parse_into_json(string)
return new_buffer
return ''