CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: UdpClient help

  1. #1
    Join Date
    Jun 2008
    Posts
    1

    Cool UdpClient help

    Hi folks. I'm new to C# so please bear with me. I have a UdpClient application that uses UdpClient.Receive. This works ok but I've been trying to get BeginReceive to work. I've read countless examples and I still don't get it. Could someone please explain very very simply how to use BeginReceive.

    Thanks in advance for your time

    Frankt

  2. #2
    Join Date
    Jan 2007
    Posts
    491

    Re: UdpClient help

    As you probably know, the Receive method blocks, i.e. the statements after it will be executed only after the message will be received (or the timeout will expire).
    Well, in most cases we will not want such thing. We want to recieve the message, and in the meantime, do other progresses.

    One solution for this problem will be creating a thread, and receive there the message. However, it's not very comfortable.

    Another, and probably easier solution will be to use the "asynchronous communication" mechanism. The BeginRecieve is part of it. This mechanism allows us to do what we did with the thread, but we'll only have to create a method - we will not have to create the thread.
    Behind the scenes, the computer will create a thread, and call the method you defined as the recieve method (one of the parameters BeginReceive gets is the name of this method) there.

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

Featured