[Mono-winforms-list] No UDP broadcast messages received

Robert Jordan robertj at gmx.net
Tue Nov 29 10:11:35 EST 2011


On 29.11.2011 14:40, sharkal wrote:
> The socket is configured something like this:
>
> Socket clientSocket = new Socket(AddressFamily.InterNetwork,
> SocketType.Dgram, ProtocolType.Udp);
> clientSocket.ReceiveBufferSize = 2 * 1024 * 1024;
> clientSocket.Bind(localEndPoint);

What IP is localEndpoint? You should rather not bind at all
if you want to receive broadcasts.

> clientSocket.BeginReceiveFrom(receivebuffer, 0, receivebuffer.Length,
>                      SocketFlags.None, ref localEndPoint, OnReceiveCallback,
> clientSocket);
>
> clientSocket.SetSocketOption(SocketOptionLevel.Socket,
> SocketOptionName.Broadcast, 1);
> clientSocket.EnableBroadcast = true;

The SetSocketOption method is likely called too late, because
you're already receiving.

Robert



More information about the Mono-winforms-list mailing list