Is there a better way to write named-pipes in F#?
- by Niran
Hi 
I am new to F#. I am trying to communicate with java from F# using named pipe. The code below works but I am not sure if there is a better way to do this (I know the infinite loop is a bad idea but this is just a proof of concept) if anyone have any idea to improve this code please post your comments.
Thanks in advance
Niran
open System.IO
open System.IO.Pipes
exception OuterError of string
let continueLooping = true
while continueLooping do
    let pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4)
    printfn "[F#] NamedPipeServerStream thread created."
    //wait for connection
    printfn "[F#] Wait for a client to connect"
    pipeServer.WaitForConnection()
    printfn "[F#] Client connected."
    try
        // Stream for the request. 
        let sr = new StreamReader(pipeServer)
        // Stream for the response. 
        let sw = new StreamWriter(pipeServer)
        sw.AutoFlush <- true;
        // Read request from the stream. 
        let echo = sr.ReadLine();
        printfn "[F#] Request message: %s" echo
        // Write response to the stream.
        sw.WriteLine("[F#]: " + echo)
        pipeServer.Disconnect()
    with
    | OuterError(str) -> printfn "[F#]ERROR: %s" str
    printfn "[F#] Client Closing."
    pipeServer.Close()