Hi all,
I want to use System.Net
and System.Net.Sockets
to broadcast UDP packets on my LAN, however, on sending the data on the socket I get an “Access denied” exception. I’m new to .Net and C#, am I doing something wrong programming wise, or is this perhaps a licensing limitation (I’m using an expired unity pro trial license, which I believe reverts to the same functionality as the free version?)
Here’s the code:
using System.Net;
using System.Net.Sockets;
using System.Text;
Boolean exception_thrown = false;
Socket sending_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress send_to_address = IPAddress.Parse("192.168.0.255");
IPEndPoint sending_end_point = new IPEndPoint(send_to_address, 25000);
string formattedString;
byte[] send_buffer = Encoding.ASCII.GetBytes(text_to_send);
formattedString = String.Format("sending to address: {0} port: {1}", sending_end_point.Address, sending_end_point.Port);
try {
Debug.Log(send_buffer);
sending_socket.SendTo(send_buffer, sending_end_point);
} catch (Exception send_exception ) {
exception_thrown = true;
formattedString = String.Format("Exception {0}", send_exception.Message);
Debug.Log(formattedString);
}