April 2020
Intermediate to advanced
294 pages
7h 53m
English
The socket_send function needs to take the packaged data and then convert it into a JSON string. This can be done using the ujson.dumps function. This function takes the received JSON data and then literally dumps it into a string that can then be transmitted. The function looks like the following:
def socket_send(Data): mystring = ujson.dumps(Data) try: s.write(mystring + "\r\n") except Exception as e: if errno.ECONNRESET: socket_connect() print(e)
You can see that once we create the string, we can access the s object, which is our socket connection, and then call the write method. If there is an error sending, then we just print it into the REPL. With this in place, we have everything we need to finally pull together the ...
Read now
Unlock full access