Lately, I have been developing this piece of code with my knowledge of networking in order to test it and see how it works.I was trying to interact with TCP servers. It goes like this:
from socket import *
bag = socket(AF_INET,SOCK_STREAM)
bag.bind(("",9000))
bag.listen(5)
while True:
c,a = bag.accept()
print ("Received connection from", a)
c.send("Hello %s\n" % a[0])
c.close()
And the console printed this out:
Traceback (most recent call last): File "/Users/spathen/PycharmProjects/untitled31/jsyk.py", line 8, in Received connection from ('127.0.0.1', 50162) c.send("Hello %s\n" % a[0]) TypeError: a bytes-like object is required, not 'str'
Process finished with exit code 1
Any ideas on why this isn't working. An I not doing this right? Is there something going on? Do I have to send datagrams with UDP instead?