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
MESSAGE = "Hello, World!"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
data = s.recv(BUFFER_SIZE)

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))
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

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.

  • 1
    try to bind on all adress : TCP_IP = "" or TCP_IP = ''? – Ephemeral Jun 25 at 19:26
  • 1
    adress starting with 92. is Class A IPv4 addr , are you behind NAT ? – Ephemeral Jun 25 at 19:28
  • 1
    get your current IPv4 on RPi: ip a show wlan0 (change wlan0 for your network interface card) , Get your IPv4 on windows : ipconfig /all and search your network interface card connected to the same network of your RPi. Then for Win client : TCP_IP = 192.168.X.X and for the RPi server : TCP_IP = '192.168.X.X' (note the same subnet) – Ephemeral Jun 25 at 19:41
  • I have tried TCP_IP = "" and it didn't work. Also, I'm not sure what the other comments mean. – Someoneludo Jul 8 at 17:56
  • What is your error with TCP_IP="" exactly ? TCP_IP_"" must be ONLY on the server part ! – Ephemeral Jul 8 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.