To open a port in an Azure role and make a successfull connection to that port from the outside you need to understand that there is always a firewall/load-balancer in front of your worker role.
So typically you must declare the port you want to make available from the internet in the "ServiceDefinition.csdef" file to make the firewall/load-balancer ready.
(this example opens TCP port 123)
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyTcpCloud" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WorkerRole name="MyTcpHost">
<ConfigurationSettings>
<Setting name="DiagnosticsConnectionString" />
</ConfigurationSettings>
<Endpoints>
<InputEndpoint name="MyEndpoint" protocol="tcp" port="123" />
</Endpoints>
</WorkerRole>
</ServiceDefinition>
Then in your code running in the worker-role you need to create a listener that connects to the load-balancer (which may use a different port number in the communication with the worker role)
TcpListener listener = new TcpListener(
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyEndpoint"].IPEndpoint);
For a complete working example that even handles load-balancing, see Maarten Balliauw excellent blog:
http://blog.maartenballiauw.be/post/2010/01/17/Creating-an-external-facing-Azure-Worker-Role-endpoint.aspx
// Ronny