I found this example in stackoverflow (link) from user3132092 for a TCP Client sending a "Hello world" string via TCP:
Sending string
import socket
host = socket.gethostname()
port = 12345 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(b'Hello, world')
The question is how does s.sendall() accepts a string as parameter the same way it accepts a binary? Is the "Hello world" converted to binary?
In this example (link) s.sendall(link) is sending a binary that was converted previously to binary using python struct. Why is the struct not necessary for the "Hello World"?
Sending binary
import struct
values = (1, 'ab', 2.7)
packer = struct.Struct('I 2s f')
packed_data = packer.pack(*values)
print >>sys.stderr, 'sending "%s"' % binascii.hexlify(packed_data), values
sock.sendall(packed_data)