c# - Access denied when sending data with UdpClient -


i trying create small application reads data serial-/com-port , broadcasts data network using port 15000.

everything works fine on windows , linux (using mono) socket exception on macos following message: access denied

i tried run application elevated permissions:

sudo mono ./serialmonitor.exe

but doesn't work too.

is there way rid of exception? , why work without issues on windows , linux?

here code:

using system; using system.io.ports; using system.net; using system.net.sockets; using system.text;  namespace serialmonitor {     class mainclass     {         static serialport mserial = new serialport();         static string[] mserialports;         static udpclient mnetwork;         static ipendpoint mip;          static string mdata = "";          public static void main(string[] args)         {             mnetwork = new udpclient();             mip = new ipendpoint(ipaddress.parse("192.168.1.255"), 15000);              mserialports = serialport.getportnames();              console.writeline("select serial port:");             if (mserialports.length == 0)             {                 console.writeline("no serial ports available!");                 return;             }             (int = 0; < mserialports.length; i++)             {                 console.writeline(i + 1 + ": " + mserialports[i]);             }             console.write("selection: ");             int selection = convert.toint32(console.readline());              console.writeline("selected port: " + mserialports[selection - 1]);              mserial.portname = mserialports[selection - 1];             mserial.baudrate = 9600;             mserial.newline = "\r\n";             mserial.open();             mserial.discardinbuffer();              console.writeline("\ndata:");              while (true)             {                 try                 {                     mainclass.mdata = mserial.readline();                     console.writeline(mainclass.mdata);                      byte[] bytes = encoding.ascii.getbytes(mainclass.mdata);                     mnetwork.send(bytes, bytes.length, mip);                 }                 catch(socketexception ex)                 {                     console.writeline("\nnetwork error: " + ex.message);                     console.read();                     return;                 }                 catch (exception ex)                 {                     console.writeline("\nerror: " + ex.message);                     console.read();                     return;                 }             }         }     } } 

i using visual studio community 2017 mac

version 7.1 (build 1297)

mono 5.2.0.215 (d15-3/da80840) (64-bit)

project configuration:

.net framework 4.6.1

x86

if want send broadcast messages across local subnet (or broadcasts in general) have enable broadcasts on socket with:

mnetwork.enablebroadcast = true; 

reference:

https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient(v=vs.110).aspx

http://answers.unity3d.com/questions/248494/socket-exception-access-denied.html


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -