Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ErsharpClient
- open System
- open Otp
- open Tinesware.Unfurling
- module Main =
- let ConnectTo serverNode cookie =
- let clientNode = new OtpSelf("clientnode", cookie)
- let serverNode = new OtpPeer(serverNode)
- clientNode.connect(serverNode)
- let ReceiveRPC (connection : OtpConnection) =
- Wrapper.ToTerm <| connection.receiveRPC()
- let MakeRPC (connection : OtpConnection) (moduleName:string) (functionName:string) (arguments: Term seq) =
- connection.sendRPC(moduleName, functionName, arguments |> Seq.map Wrapper.ToOtpObject |> Seq.toArray)
- ReceiveRPC connection
- let StartGenServer (connection : OtpConnection) =
- match MakeRPC connection "mathserver" "start_link" [] with
- | Term.Tuple [ Term.Atom "ok" ; pid ] -> pid
- | Term.Tuple [ Term.Atom "error"; Term.Tuple [ Term.Atom "already_started" ; pid2 ]] -> pid2
- | start -> raise (new System.InvalidOperationException(start.ToString()))
- [<EntryPoint>]
- let Main arguments =
- let connection = ConnectTo "servernode@YourNodeNameHere" "cookie"
- let pid = StartGenServer connection
- let args = [6I; 9I]
- |> Seq.map Term.Integer
- match MakeRPC connection "mathserver" "multiply" args with
- | Term.Tuple [ Term.Atom "ok" ; Term.Integer value ] ->
- Console.WriteLine("Return Value:" + value.ToString())
- | result -> Console.WriteLine("Failure:" + result.ToString())
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement