Thanks a lot to Don and Robert. Both your solutions look great. :)

By on 7/26/2007 6:18 AM ()

You can use the functions output_value and input_value from the pervasises module to serialise a value of any type to a stream. This stream could be a BinaryWriter/BinaryReader writing to a TCP stream created via class in the Sytem.Net namespace.

Under the hood, output_valye and input_value use a framework class System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, so you can also use this directly.

Cheers,
Rob

By on 7/26/2007 6:08 AM ()

Use .NET BinarySerialization, and .NET streams as replacements for channels. e.g.

--> open stream using System.IO.File.OpenRead, System.IO.File.OpenWrite

Helpful snippets:

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

open System.IO

let output (os:Stream) (x: 'a) = 
    let formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() in
    formatter.Serialize(os,box [x]);
    flush os


let input (is:Stream) = 
    let formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter() 
    let res = formatter.Deserialize(is) 
    match ((unbox res) : 'a list) with 
    | [x] -> x
    | _ -> failwith "input_value: expected one item"

We serialize a list just in case the input value is null, in which case the .NET APIs would otherwise raise an exception.

Don

By on 7/26/2007 5:57 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