Both of your first two questions have the same answer.

The IPEndPoint parameter is on EndReceive - presumably it is an "out" parameter. As a result, you can do something like this

1
2
3
4
5
6
  member x.AsyncReceive() =
    let fauxEndReceive iar = 
        let mutable IPE : IPEndPoint = null
        let r = x.EndReceive(iar, &IPE)
        r, IPE
    Async.BuildPrimitive(x.BeginReceive, fauxEndReceive)

Now AsyncReceive returns an Async of a tuple of the byte array and the IPEndpoint.

As for timeouts, I think you can use a function like

1
2
3
4
let AddTimeoutToAsync anAsync timeout =
    async {
        return Async.Run(anAsync, timeout=timeout)
    }

to add a timeout to any async operation, though I haven't thought deeply enough about it (I think this may block an extra thread)...

By on 10/7/2008 7:51 AM ()

As per your suggestions, the following works great.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 

#light

open System
open System.Net
open System.Net.Sockets

type System.Net.Sockets.UdpClient with
  member x.AsyncSend(data:byte[], count:int) =
    Async.BuildPrimitive(data, count, x.BeginSend, x.EndSend)

  member x.AsyncReceive(ipe:ref<IPEndPoint>, ?timeout) =
    async
      { let endReceive iar = x.EndReceive(iar, ipe)
        let task = Async.BuildPrimitive(x.BeginReceive, endReceive)
        return Async.Run(task, ?timeout=timeout)
      }

Thanks a lot !!!

By on 10/7/2008 8:12 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper