Skip to content

Can't establish socket connection on ec2 instance for integrated webcam

0

I'm trying to connect to my ec2 instance through sockets to stream my laptop's webcam but I can't seem to do it for some reason. I managed to get my scripts to work by running them both on my machine. But if I try to run the client_side.py on ec2 instance I get an error. Please look at this video showing my process https://we.tl/t-lqsrI0w5Yl , the video doesn't show any sensitive information about the device I am using or any other private information such as IP address, instance Id etc. I made sure to blur out all sensitive information throughout the entire video

Now I will give some data on the parameters, while not compromising security, but I believe this is needed to better understand what I'm doing

server_side.py

HOST = ' ' #this I left blank

PORT = somenumber

client_side.py

clientsocket.connect(('elastic-IP',somenumber))

note: somenumber is the same for both files, I hope this is correct

My ec2 instance is public and I have attached an elastic-IP to it since I found out that everytime I close and re-open it the default one will change. This elastic-IP is what I'm passing to the client_side.py(which I run inside the ec2 instance), while to the server_side.py(which I run on my laptop) I am leaving the HOST parameter empty, I am not sure this is correct tho but don't know what else I should put there, I have very little knowledge on how sockets and IPs work :(

I terminated my ec2 instance yesterday because I had modified some values and it got quite confusing so I wanted a clean fresh start with only the essentials. I let pretty much everything on default so now I believe I'm running my new instance on a public IP, modified to become an elastic-IP. I connect to it through SSH protocol, via RemoteDesktop app. I have internet connection to it.

I am very much in the dark with this whole process, I thought if I re-booted my machine and gave it an elastic-IP this time it would surely work but it still doesn't. I've looked at all kinds of posts online describing how people managed this connection, I followed every step but nothing happens. What am I doing wrong?

asked 2 years ago250 views

1 Answer
0

Based on the information provided, it seems you're encountering issues with socket connections between your local machine and an EC2 instance for webcam streaming. Here are some key points to consider:

  1. EC2 instances don't have direct access to local hardware like webcams. You can't directly access your laptop's webcam from an EC2 instance.

  2. For your server-side script running on your laptop, leaving the HOST parameter blank ('') is correct. This allows the server to listen on all available network interfaces.

  3. For the client-side script running on the EC2 instance, using the Elastic IP is correct.

  4. Ensure that your EC2 instance's security group allows inbound traffic on the port you're using for the socket connection. You need to add a custom TCP rule for your specific port.

  5. Check that your local firewall isn't blocking outgoing connections on the port you're using.

  6. Verify that the port number is the same in both server and client scripts.

  7. Make sure your EC2 instance is in a public subnet with an Internet Gateway attached to allow outbound internet access.

To troubleshoot:

  1. Test basic connectivity by pinging your EC2 instance from your local machine.

  2. Try using a well-known port (like 80) temporarily to rule out port-specific issues.

  3. Use a tool like netcat to test the socket connection independently of your Python script.

  4. Check EC2 instance logs for any error messages related to the connection attempt.

If you're still unable to establish a connection, you might want to consider alternative approaches:

  1. Capture the webcam feed locally and upload the video to the EC2 instance for processing.

  2. Use a cloud service designed for video ingestion and processing, then have your EC2 instance work with that service instead of directly with your local webcam.

Remember, streaming directly from a local webcam to an EC2 instance can be complex due to networking and security constraints. You may need to explore more robust solutions designed for cloud-based video processing if this is a critical requirement for your application.
Sources
Webcam Streaming EC2 | AWS re:Post
EC2 instance failed to connet | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.