Oppure

Loading
Questo topic e' stato chiuso dal moderatore.
01/10/11 13:23
jaco94++
Salve a tutti!

Volevo sapere come mai inviando in broadcasting un datagram in UDP all'indirizzo 255.255.255.255 il programma si rifiuta di inviarlo mentre se lo invio a 192.168.1.255 lo invia normalmente e tutti gli altri pc sulla mia rete locale ricevono il datagram senza problemi! sto utilizzando questo codice:

 
Socket rq = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            IPAddress broadcast = IPAddress.Broadcast;
            byte[] buffer = Encoding.ASCII.GetBytes("RQ");
            IPEndPoint endt = new IPEndPoint(broadcast, 9000);
            rq.SendTo(buffer, endt);


Come posso risolvere :-?
aaa
01/10/11 14:28
L'errore che ottieni è

"WSAEACCES (10013) - An attempt was made to access a socket in a way that is forbidden by its access permissions.

This error occurs when a broadcast address is used for sendt but the broadcast permission is not set by using setsockopt(SO_BROADCAST)."


quindi devi usare prima una

rq.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);