Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ErsharpClient
- open System
- open Otp
- module Main =
- let (|Atom|_|) text (term : Erlang.Object) =
- match term with
- | :? Erlang.Tuple as tuple ->
- let terms = tuple.elements()
- if terms.Length <> 2 then
- None
- else match terms.[0] with
- | :? Erlang.Atom as atom ->
- if atom.atomValue() = text then Some(terms.[1])
- else None
- | _ -> None
- | _ -> None
- let ConnectTo serverNode cookie =
- let clientNode = new OtpSelf("clientnode", cookie)
- let serverNode = new OtpPeer(serverNode)
- clientNode.connect(serverNode)
- let StartGenServer (connection : OtpConnection) =
- connection.sendRPC("mathserver", "start_link", Array.empty<Otp.Erlang.Object>)
- let start = connection.receiveRPC()
- match start with
- | Atom "ok" pid -> pid
- | Atom "error" value ->
- match value with
- | Atom "already_started" pid2 -> pid2
- | _ -> raise (new System.InvalidOperationException(start.ToString()))
- | _ -> raise (new System.InvalidOperationException(start.ToString()))
- [<EntryPoint>]
- let Main arguments =
- let connection = ConnectTo "servernode@YourNodeNameHere" "cookie"
- let pid = StartGenServer connection
- let args = [| new Otp.Erlang.Long(6L); new Otp.Erlang.Long(9L)|] : Otp.Erlang.Object array
- connection.sendRPC("mathserver", "multiply", args);
- let result = connection.receiveRPC()
- match result with
- | Atom "ok" value -> Console.WriteLine("Return Value:" + value.ToString())
- | _ -> Console.WriteLine("Failure:" + result.ToString())
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement