Greetings,
The script below works well for one of my embedded sensing systems:
The script below works well for one of my embedded sensing systems:
import socket TCP_IP = 'X.X.X.X' TCP_PORT = MY_PORT BUFFER_SIZE = 1024 MESSAGE = "MY_MESSAGE" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) MESSAGE = MESSAGE.encode('utf8') s.send(MESSAGE) data = s.recv(BUFFER_SIZE) s.close() print("received data:", data)For another one, I was unable to connect to it using the same approach. The script below shows another way to do this:
import socket TCP_IP = 'X.X.X.X' TCP_PORT = MY_PORT BUFFER_SIZE = 1024 s = socket.create_connection((TCP_IP, TCP_PORT)) MESSAGE = "MY_MESSAGE" MESSAGE = MESSAGE.upper() MESSAGE = MESSAGE.encode("utf-8") s.sendall(MESSAGE) while True: data = s.recv(BUFFER_SIZE) if not data: break print("Received data:", data) print("Data string:", data.decode("utf-8")) ''' data = s.recv(BUFFER_SIZE) print("Received data:", data) if data: datastring = data.decode("utf-8") print("Data string:", datastring) s.close() '''Somehow, I don't receive any response back... Any ideas why?