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 class question? (How to release the bound port) [modified]

UdpClient class question? (How to release the bound port) [modified]

Scheduled Pinned Locked Moved C#
questionhelptutorialannouncement
2 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.
  • Z Offline
    Z Offline
    zafersavas
    wrote on last edited by
    #1

    Hi all, I have a problem with the udpClient class. Here are the details. I am creating an instance of udpClient class with the following constructer; UdpClient myUdp = new UdpClient(); // I don't want to use the constructer "UdpClient myUdp = new UdpClient(localPortNo);" So 1) what is the method that I should call to assign my listening port (local port number) for incoming udp packets? 2) How can unbind the port without deallocating all the sources related to the socket? i.e If I close my socket with the "close()" method than all the resources related to the socket are made free. Instead I just want to release the local port. Best Regards zafersavas -- modified at 18:08 Saturday 24th February, 2007

    W 1 Reply Last reply
    0
    • Z zafersavas

      Hi all, I have a problem with the udpClient class. Here are the details. I am creating an instance of udpClient class with the following constructer; UdpClient myUdp = new UdpClient(); // I don't want to use the constructer "UdpClient myUdp = new UdpClient(localPortNo);" So 1) what is the method that I should call to assign my listening port (local port number) for incoming udp packets? 2) How can unbind the port without deallocating all the sources related to the socket? i.e If I close my socket with the "close()" method than all the resources related to the socket are made free. Instead I just want to release the local port. Best Regards zafersavas -- modified at 18:08 Saturday 24th February, 2007

      W Offline
      W Offline
      Wayne Phipps
      wrote on last edited by
      #2

      You haven't said why you don't want to use the overloaded constructor to instanciate the client and specify the port. The problem is that in order to listen for incoming data, you use the UdpClient.Receive method. This method blocks until data is received, and with UDP being a connectionless protocol, you can never guarantee when data will be recieved so your left with having to listen for any/all incoming data over a specific port. One way to achieve this is to run a UdpClient that listens for incoming data on a seperate thread which frees up the main thread to do it's normal work. A seperate UdpClient can then be instanciated in the main thread whenever you need to send data. I created a test project some time ago which you can download from here: http://www.box.net/public/frq1a08ozh It requires v2.0 of the .Net Framework but the source code should help point you in the right direction even if you using v1.1 Hope this helps

      Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog

      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