Advertisement
Guest User

Untitled

a guest
May 27th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. namespace ErsharpClient
  2.  
  3. open System
  4. open Otp
  5. open Tinesware.Unfurling
  6.  
  7. module Main =
  8.  
  9. let ConnectTo serverNode cookie =
  10. let clientNode = new OtpSelf("clientnode", cookie)
  11. let serverNode = new OtpPeer(serverNode)
  12. clientNode.connect(serverNode)
  13.  
  14. let ReceiveRPC (connection : OtpConnection) =
  15. Wrapper.ToTerm <| connection.receiveRPC()
  16.  
  17. let MakeRPC (connection : OtpConnection) (moduleName:string) (functionName:string) (arguments: Term seq) =
  18. connection.sendRPC(moduleName, functionName, arguments |> Seq.map Wrapper.ToOtpObject |> Seq.toArray)
  19. ReceiveRPC connection
  20.  
  21. let StartGenServer (connection : OtpConnection) =
  22. match MakeRPC connection "mathserver" "start_link" [] with
  23. | Term.Tuple [ Term.Atom "ok" ; pid ] -> pid
  24. | Term.Tuple [ Term.Atom "error"; Term.Tuple [ Term.Atom "already_started" ; pid2 ]] -> pid2
  25. | start -> raise (new System.InvalidOperationException(start.ToString()))
  26.  
  27. [<EntryPoint>]
  28. let Main arguments =
  29. let connection = ConnectTo "servernode@YourNodeNameHere" "cookie"
  30. let pid = StartGenServer connection
  31.  
  32. let args = [6I; 9I]
  33. |> Seq.map Term.Integer
  34.  
  35. match MakeRPC connection "mathserver" "multiply" args with
  36. | Term.Tuple [ Term.Atom "ok" ; Term.Integer value ] ->
  37. Console.WriteLine("Return Value:" + value.ToString())
  38. | result -> Console.WriteLine("Failure:" + result.ToString())
  39.  
  40. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement