나는 F #을 처음 사용합니다. 나는 명명 된 파이프를 사용하여 F #에서 java와 통신하려고합니다. 아래의 코드는 작동하지만 더 좋은 방법이 있는지는 잘 모르겠습니다. (무한 루프는 나쁜 생각이지만 개념의 증거 일뿐입니다.) 누군가이 코드를 개선하기위한 아이디어가 있다면 의견을 게시하십시오. . 사전 SudalyF #에서 명명 된 파이프를 작성하는 더 좋은 방법이 있습니까?
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()