Amazon EC2 – How to Open a Socket on an Instance

amazon ec2amazon-web-servicessocketwebsocket

I want to send webcam video from my laptop to aws EC2 instance.

I'm trying to follow suggestions from here and code from here.

The issue I'm facing is that I do not know how to open a socket and listen to incoming traffic on EC2. My EC2 is a Amazon Linux free tier instance. No matter what I try I can't get it to work.

I added an inbound rule to allow TCP traffic on the port I want to listen to.

If it helps, binding to a port doesn't seem to be an issue but it seems that the code gets stuck on socket.accept() line of code from link 2.

I would appreciate if somebody showed me how to do this properly.

Best Answer

If it's stuck in socket.accept() it means it's waiting for connection. In the client script what IP are you connecting to? It must not be localhost, nor the instance private IP (e.g. 172.31.x.x) but instead its Public IP address - you can find it in the EC2 details. Also note that the Security Group must be open from your laptop's public IP (or from all IPs but that's far less secure).

Related Topic