So I made a simple client / server script using python sockets, and it's been working great on my PC. I decided I'd try to move the server over to a raspberry pi so it would be dedicated, and it's not working out so great.
import socket from modules import * def server_program(): host = socket.gethostbyname(socket.gethostname()) port = 5000 server_socket = socket.socket() server_socket.bind((host, port)) print("Server is online. Awaiting commands. ") while True: server_socket.listen(2) conn, address = server_socket.accept() print("Connection from: " + str(address)) data = conn.recv(1024).decode() print("\tReceived data:", data) conn.send("success".encode()) execute_data(data, server_socket) if __name__ == '__main__': print() server_program()
import socket def client_program(): # host = socket.gethostname() # local device: This works on both devices # host = '192.168.0.30' # working computer: This works on my PC host = '192.168.0.44' # raspberry pi: This does NOT work on my Pi port = 5000 client_socket = socket.socket() client_socket.connect((host, port)) message = "roku remote back" client_socket.send(message.encode()) data = client_socket.recv(8).decode() print('Received from server: ' + data) client_socket.close() if __name__ == '__main__': print() client_program() try: pass # This is where client_program() was, I moved it out to see the full error except ConnectionRefusedError: print("The server doesn't appear to be online.\n")
I'm getting this connection error, but I really don't understand why. I'm not super conversant in RaspPi, so I'm sure there's something I'm missing. Thanks for any and all help!