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