In my iOS application, I am trying to invoke a TcpListener
instance. I define and start the listener as follows:
var listener = new TcpListener(IPAddress.Any, 104);
listener.Start();
However, I get the following exception when I run this code (iOS Simulator, iPhone, Debug mode):
System.Net.Sockets.SocketException: Access denied at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00051] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1111 at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00022] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/TcpListener.cs:259 at System.Net.Sockets.TcpListener.Start () [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/TcpListener.cs:239 at
...
Is there anything I can do to avoid the Access denied error, or is this a built-in restriction of the Mono runtime on Xamarin.iOS?
you can't bind to ports < 1024
without administrative privileges. Use a port >= 1024
for this purpose. This is a general restriction - you would encounter the same problem on any application if running as an ordinary user in most operating systems.
This is noted in the wikipedia page for DICOM, where it gives the list of ports:
DICOM have reserved the following TCP and UDP port numbers by the Internet Assigned Numbers Authority (IANA):
104
well-known port for DICOM over Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). Since 104 is in the reserved subset, many operating systems require special privileges to use it.2761
registered port for DICOM using Integrated Secure Communication Layer (ISCL) over TCP or UDP2762
registered port for DICOM using Transport Layer Security (TLS) over TCP or UDP11112
registered port for DICOM using standard, open communication over TCP or UDPThe standard recommends but does not require the use of these port numbers.
(page from wikipedia, emphasis mine)
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