Dec-11-2020, 09:17 AM
(This post was last modified: Dec-11-2020, 09:17 AM by ATARI_LIVE.)
I want to test to see if works, here what I am trying and did not work, why? Byte?
Here for CLIENT:
Here for CLIENT:
import socket TCP_IP = '127.0.0.1' TCP_PORT = 5005 BUFFER_SIZE = 1024 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send('HELLO WORLD') data = s.recv(BUFFER_SIZE) s.close() print ("received data:", data)Here for SERVER:
import socket TCP_IP = '127.0.0.1' TCP_PORT = 5005 BUFFER_SIZE = 20 # Normally 1024, but we want fast response s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((TCP_IP, TCP_PORT)) s.listen(1) conn, addr = s.accept() print ('Connection address:', addr) while 1: data = conn.recv(BUFFER_SIZE) if not data: break print ("received data:", data) conn.send(data) # echo conn.close()On CLIENT message said:
Output:Traceback (most recent call last):
File "client.py", line 11, in <module>
s.send('HELLO WORLD')
TypeError: a bytes-like object is required, not 'str'
THANKS!