sending socket data as hex?

  • Hi,

    with send() I can only send strings, right? But I want to send hex data, how can I do this?

    My sample code:

    import socket

    host = '' # laptop running server
    port = 2004
    addr = socket.getaddrinfo(host, port)[0][-1]
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.send('ffff') <- at this point I don't want to send ffff as text but as hex

  • Pybytes Beta


    You should use binary data.

    For binary use the following format.

    For hex:

    import binascii

    Or do you want this?

    s.send(int('0xffff', 16))

Log in to reply

Pycom on Twitter