Results 1 to 6 of 6

Thread: UdpClient.Receive troubles

  1. #1

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    UdpClient.Receive troubles

    Just playing with udp, was going to make two console apps, one to send a message the other to receive.

    The example found under "UdpClient.Receive Method", just copied and pasted into an empty class, always gives me a SocketException: An invalid argument was supplied.

    Can someone tell me what I'm missing?

    Thanks,
    Mike

  2. #2
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    That example is a bad example. When you declare the UDPClient you need to bind it to the local end point.

    Change your
    Code:
    Dim receivingUdpClient As New UdpClient
    to something like this...

    Code:
    Dim receivingUdpClient As New UdpClient(New IPEndPoint(IPAddress.Parse("127.0.0.1"), 0))
    HTH

  3. #3
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    One more thing, the receive method is blocking so you might want to include that in a thread.

  4. #4

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Thanks, MagellanTX, that did the trick. I've seen other bad examples from MSDN (specifically with Sockets), but I've been able to figure it out myself. Much appreciated.

    FWIW, right now I don't care about the blocking business as it's just a test program. Once I figure out what I want, I'll either put it in a thread, or see if there's an asynchronous method available.

    Thanks again,
    Mike

  5. #5
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    352
    MagellanTX: Thanks for this post!

    Mike Hildner: Just out of curiosity, how did you finally solve the problem? Asyncronous or threaded?
    Thanks,
    Eric
    --------------------------------------------------------------------------------------------------------------------
    VB.net/C# ... Visual Studio 2019
    "None of us are as smart as all of us."

  6. #6

    Thread Starter
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I never took it very far, so never bothered with programming anything asynchronous. I've worked with asynchronous TCP sockets, though.

    I was thinking of using UDP for notification when a 911 call came in in a dispatch center. That way, everyone who is subscribing can get a message. But now I'm thinking of using message queues or something, not really sure of the best way. Haven't gotten to that part of the project yet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width