Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. UdpClient error

UdpClient error

Scheduled Pinned Locked Moved C#
questioncsharphelpannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sjembek
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • S sjembek

      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

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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

      **

      S 1 Reply Last reply
      0
      • L leppie

        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

        **

        S Offline
        S Offline
        sjembek
        wrote on last edited by
        #3

        No luck, unfortunately, I get the same error-message :(.

        L 1 Reply Last reply
        0
        • S sjembek

          No luck, unfortunately, I get the same error-message :(.

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          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

          **

          S 1 Reply Last reply
          0
          • L leppie

            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

            **

            S Offline
            S Offline
            sjembek
            wrote on last edited by
            #5

            Yep, that's what I did, and that works. But I'd still like to know what the problem is, there's no reason this shouldn't work.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups