I have been trying to send data from my Windows PC to my Raspberry Pi 3 for a python controlled speaker project. I am using TCP sockets which I don't know much about.
Client code (PC):
import socket TCP_IP = '92.***.***.**' TCP_PORT = 5005 BUFFER_SIZE = 1024 MESSAGE = "Hello, World!" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((TCP_IP, TCP_PORT)) s.send(MESSAGE) data = s.recv(BUFFER_SIZE) s.close() print("received data:", data)
Server code (Raspberry Pi):
import socket TCP_IP = "92.***.***.**" TCP_PORT = 5005 BUFFER_SIZE = 20 #NOrmally 1024 but we want a 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("Connction address: ", addr) while 1: data = conn.recv(BUFFER_SIZE) if not data: break print("received data: ", data) conn.send(data) #echo conn.close()
When I run this, it comes up with this error on Server.py:
Traceback(most recent call last): File "/home/pi/Server.py", line 9, in <module> s.bind((TCP_IP, TCP_PORT)) OSError: [Errno 99] Cannot assign requested address
I have checked and rechecked and each of the IP addresses is the servers (Raspberry Pi's) IP address.