UdpClient error
-
Hi, I've implemented a class (see below) to handle communications for multiple objects that use a separate thread to handle UDP communications over the same ports using the UdpClient class (.net 2.0). To be sure only one instance can be made for each port I've implemented this in a static way. As you can see below this looks relatively simple. However, once I've started listening for data using "listen" and the callback is made, the EndReceive (I marked it below) method gets me an error: "The I/O operation has been aborted because of either a thread exit or an application request" I've checked for possible thread abortion, but I'm sure this isn't the case. So my question is: what causes this error? Also, I don't see why it's necessary to pass a reference to the endpoint in the EndreceiveMethod: Isn't the callback made because data was received from a known endpoint? Does the endreceive method update the endpoint passed to the endpoint the data was actually received from (so that I can delegate this to my evenlisteners)? I've checked MSDN docs on "EndReceive" but they don't comment on this. Any comments or suggestions are very welomce, thanks in advance!
class LineConnection { static UdpClient receiver = new UdpClient(5048); static UdpClient sender = new UdpClient(5049); public delegate void DataReceivedDelegate(byte[] d, IPEndPoint endpoint); public static event DataReceivedDelegate DataReceived; public static bool receiving; /// /// sends the bytes to the specified endpoint /// /// bytes to send /// target endpoint public static void Send(byte[] b, IPEndPoint ipe) { sender.Send(b, b.Length, ipe); } /// /// Starts listening for data at port 5048 /// public static void listen() { if (!receiving) { receiver.BeginReceive(ReceivedData, null); } } /// /// callback called when data is received, notifies listeners data was received /// /// asynchronous operation status private static void ReceivedData(IAsyncResult result) { if (result.IsCompleted) { try { receiving = fal
-
Hi, I've implemented a class (see below) to handle communications for multiple objects that use a separate thread to handle UDP communications over the same ports using the UdpClient class (.net 2.0). To be sure only one instance can be made for each port I've implemented this in a static way. As you can see below this looks relatively simple. However, once I've started listening for data using "listen" and the callback is made, the EndReceive (I marked it below) method gets me an error: "The I/O operation has been aborted because of either a thread exit or an application request" I've checked for possible thread abortion, but I'm sure this isn't the case. So my question is: what causes this error? Also, I don't see why it's necessary to pass a reference to the endpoint in the EndreceiveMethod: Isn't the callback made because data was received from a known endpoint? Does the endreceive method update the endpoint passed to the endpoint the data was actually received from (so that I can delegate this to my evenlisteners)? I've checked MSDN docs on "EndReceive" but they don't comment on this. Any comments or suggestions are very welomce, thanks in advance!
class LineConnection { static UdpClient receiver = new UdpClient(5048); static UdpClient sender = new UdpClient(5049); public delegate void DataReceivedDelegate(byte[] d, IPEndPoint endpoint); public static event DataReceivedDelegate DataReceived; public static bool receiving; /// /// sends the bytes to the specified endpoint /// /// bytes to send /// target endpoint public static void Send(byte[] b, IPEndPoint ipe) { sender.Send(b, b.Length, ipe); } /// /// Starts listening for data at port 5048 /// public static void listen() { if (!receiving) { receiver.BeginReceive(ReceivedData, null); } } /// /// callback called when data is received, notifies listeners data was received /// /// asynchronous operation status private static void ReceivedData(IAsyncResult result) { if (result.IsCompleted) { try { receiving = fal
sjembek wrote:
IPEndPoint end = new IPEndPoint(IPAddress.Any, 5048);
Try:
IPEndPoint end = null;
**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
sjembek wrote:
IPEndPoint end = new IPEndPoint(IPAddress.Any, 5048);
Try:
IPEndPoint end = null;
**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
Try running the receive syncronous and in another thread.**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
Try running the receive syncronous and in another thread.**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**