I would like to reach my Raspberry Pi 2 from my PC or from PC to Raspberry Pi 2 via Ethernet cable. I aim to send/receive simple data(like "Hello world") in that way. I`ve tried some python code below. When I determine PC as server, I get " OSError: [WinError 10049] The requested address is not valid in its context " error message and when I determine Raspberry Pi as server I receive " error: [Errno 99] Connot assign requested address " error message.
Obliviously I don`t receive any error when I determine local IP 127.0.0.1 but code is broken on " conn, addr = s.accept() " line.
If I mention to Client side of this code, I do not get any error message for both but I realized that code is broken on "s.send(MESSAGE)" line.
I also tried this code on the link Server and client between PC and Raspberry Pi then same issue occur, I get same errors. I`ve been working to solve this for a long time. I hope some one can help me. Thank you so much for your help.
Client:
import socket
TCP_IP = '192.168.137.226' # this IP of my pc. When I want raspberry pi 2`s as a client, I replace it with its IP '169.254.54.195'
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:
import socket
TCP_IP = '192.168.137.226' # this IP of my pc. When I want raspberry pi 2`s as a server, I replace it with its IP '169.254.54.195'
TCP_PORT = 5005
BUFFER_SIZE = 20 # Normally 1024, but I 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()