I tried to send a hexcode string using the socket
module in python. I wrote the following:
import socket
HOST = '192.168.140.2'
PORT = 55000
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
while True:
DATA = '\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff\x00\xff \x00\xff\x00\xff\x00\xff\x00'
s.sendall(DATA)
data = s.recv(4096)
s.close()
But it shows this error:
Traceback (most recent call last):
File "E:\Python\echo-client.py", line 9, in <module>
s.sendall(DATA)
TypeError: a bytes-like object is required, not 'str'
When I send a single hexcode, using s.sendall(b'\xff')
, it works.
How can I send a hex string to a server?