Note that there are some explanatory texts on larger screens.

plurals
  1. POUDP in C# works on Windows but not Linux
    primarykey
    data
    text
    <p>I'm using mono to build a C# program that needs to send and receive using UDP. Currently my implementation works as expected on Windows but I have issues getting communication to work with my Ubuntu or Fedora systems.</p> <p>Windows can broadcast and receive it's own datagrams. <br/> Ubuntu can broadcast and receive it's own datagrams. It's broadcasts are received by Windows but <em>it doesn't see datagrams broadcast by Windows.</em> <br> Fedora can broadcast but does not receive datagrams from anywhere (not even itself). It's broadcasts are received by Windows.</p> <p>When datagrams fail to reach either of the linux machines, the 'receive' function is never fired.</p> <p>This is what I have so far:</p> <pre><code>int _port = 4568; var server = new UdpClient(_port); var send_UDP = new UdpClient(); </code></pre> <p>The receive method uses the asynchronous calls of the UDPClient;</p> <pre><code>private static void receive() { server.BeginReceive(new AsyncCallback(receive), null); } private static void receive(IAsyncResult o) { try { // I'm told that port = 0 should receive from any port. var sender = new IPEndPoint(IPAddress.Any, 0); var data = server.EndReceive(o, ref sender); receive(); var str = new string(Encoding.ASCII.GetChars(data)); postmessage(sender.Address.ToString() + ":" + sender.Port.ToString() + " &gt; " + str); } catch {} } </code></pre> <p>And the send method;</p> <pre><code>public static void send(string message) { var target = new IPEndPoint(IPAddress.Parse("255.255.255.255"), _port); byte[] data = Encoding.ASCII.GetBytes(message); send_UDP.Send(data, data.Length, target); } </code></pre> <p>After some testing with Fedora, it seems to be an issue with the use of 255.255.255.255 to broadcast. Is there some other way to do this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload