'Python Socket [Winerror 10049] On amazon windows instance

Trying to use a python socket to send images from my local computer to an Amazon ec2 windows instance.

I am using the public IP from the dashboard and running into the error "OSError: [WinError 10049]" Local computer code:

import socket

# You run this second
# This will go on Jetson Nano

# AF_INET = IPv4, SOCK_STREAM = TCP
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

client.connect(('EC2 public IP', 1256))

file = open('apple.jpg', 'rb')
image_data = file.read(4096)

while image_data:
    client.send(image_data)
    image_data = file.read(4096)

file.close()
client.close()

Amazon EC2 windows code:

import socket

# You Run this first
# this will go on EC2 server

# AF_INET = IP, SOCK_STREAM = TCP
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server.bind(('Public Ip value', 1256)) #Im am using public ip from ec2 dashboard
print("Waiting for connection.")
server.listen()

client_socket, client_address = server.accept()

file = open('apple_SENT_5.jpg', "wb")
image_chunk = client_socket.recv(4096)  # stream-based protocol

while image_chunk:
    file.write(image_chunk)
    image_chunk = client_socket.recv(4096)

file.close()
client_socket.close()

On my amazon security inbound/outbound rules I have:

inboundoutbound

The firewalls are turned off on both devices as well

and the error I am getting from the EC2 server-side is

OSError: [WinError 10049] The requested address is not valid in its context


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source