I'm trying to launch a simple socket server on Amazon Web Services, but I get an error message when trying to bind the socket like this:
var s:Socket = new Socket();
s.bind(new Host("Public AWS image IP here"), 5000);
The error is std@socket_bind exception. What am I doing wrong? Am I misusing IP address or do I need to open 5000 port? I'm a complete beginner.
UPD: I've changed IP address to 0.0.0.0, the server has started successfully, however, a client still can't connect to server:
s.connect("AWS Public IP", 5000);
But why? As I have figured out, binding to 0.0.0.0 should bind the socket to all of IPs available and there is a rule in my AWS console to allow all the connections to port 5000
If you are trying to bind the EC2 Public IP, you cannot as the public IP is not assigned to your network interface. You would bind the private IP address. The EC2 instance does not know anything about the public IP address assigned "logically" to it.
The AWS Internet Gateway (IGW) is a special type of 1 to 1 NAT gateway for public to private address mapping. This means that the public IP address is assigned to the public side of the gateway and not to your EC2 instance. Your EC2 instance receives a private IP address and this is the address that you can use in your bind()
call.
However, the better choice is to bind 0.0.0.0
as this means bind to all network interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With