I am trying to write a very basic server (for experimenting purposes) that listens to incoming connections on a port and when a client connects send a custom byte sequence to the client. However I am prompted with a type exception:
TypeError: string argument without an encoding
import socket
import sys
HOST = '127.0.0.1'
PORT = 1337
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((HOST, PORT))
except socket.error as msg:
sys.exit()
s.listen(10)
conn, addr = s.accept()
print ('Connected with ' + addr[0] + ':' + str(addr[1]))
s.send(bytes('\x01\x02\x03'))
s.close()
Do I need to tell the socket somehow to send it as ascii or what am I doing wrong?
bytes('\x01\x02\x03', 'ascii')s.send(b'\x01\x02\x03')?