0

I'm trying to establish a simple socket connection (tcp://localhost:9999) from an Azure WebSite (free). I'm not aware of any restriction about socket usage, so I tried this:

public class TestSocketController : ApiController
{
    public string Get()
    {
        try
        {
            using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                socket.Connect("localhost", 9999);
                socket.Close();
                return "ok";
            }
        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }
}

Which gives the following output:

System.Net.Sockets.SocketException (0x80004005): An attempt was made to access a 
socket in a way forbidden by its access permissions 127.0.0.1:9999   
at System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port)
at System.Net.Sockets.Socket.Connect(String host, Int32 port)   
at WebApiContainer.Controllers.TestSocketController.Get()

Is there something particular to do to establish a socket connection from a website ? Binding works fine on Azure but Connect doesn't work.

Thanks

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Eric Boumendil
  • 2,318
  • 1
  • 27
  • 32

1 Answers1

2

Thanks to Benjamin's comment, I found this SO answer: it seems not to be possible for an Azure WebSite to establish TCP connection on other than standard ports 80/443, even on the loopback interface.

[Edit: for the record, named pipes do not work either with WebSites.]

So I'm probably stuck with the Service Bus.

Community
  • 1
  • 1
Eric Boumendil
  • 2,318
  • 1
  • 27
  • 32
  • So did you end up using a web role? – johnnyRose Sep 16 '15 at 16:10
  • No it's a very little project so I stay with Shared Instances websites. I think the choices I have are: Azure Service Bus (with fees) or a job with periodical checks on file system (or maybe a FileSystemWatcher). – Eric Boumendil Sep 18 '15 at 09:48