问题
I am using alchemy websockets and figured out enough to get something working on windows. I built alchemy on linux (ubuntu) with mono and ran my server. It gets a socket error. The port is >1k (port 8005 to be exact)
Unhandled Exception: System.Net.Sockets.SocketException: Access denied
at System.Net.Sockets.Socket.Bind (System.Net.EndPoint local_end) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start (Int32 backlog) [0x00000] in <filename unknown>:0
at System.Net.Sockets.TcpListener.Start () [0x00000] in <filename unknown>:0
at Alchemy.TcpServer.Listen (System.Object state) [0x00000] in <filename unknown>:0
From the filename it looks like i forgot to build with debug information or didnt install symbols but i did successfully build on mono. Its using .NET 4.0 mono 2.10
Why am i getting access denied on sockets?
回答1:
A few things to check out
netstat -a | grep 8005 See if something else is using port 8005
Run as su to see if it's a permission problem
sudo mono YourProgram.exe
I didn't take a good look at the library you are using, but if it uses ICMP or Raw Sockets it has to run as root.
Another thing to look at is to see if the DNS resolution you are using matches. Sandboxed runtimes normally only complain about this, but I've seen stranger things happen and you haven't given us much information to go on.
If it is a root problem and not that another program is using port 8005 you might be able to get away with using setcap on the mono binary so you don't have to run it as root.
Run this as root:
setcap cap_net_raw=iep /path/to/mono
回答2:
As answered at Access denied for Alchemy WebSocket creation in Linux/Mono
Alchemy throws up a Flash Policy file at 843 - try turning off the flashsocketpolicy when instantiating your server.
来源:https://stackoverflow.com/questions/10254954/mono-linux-socket-denied