Advertisement
Guest User

Untitled

a guest
May 27th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. namespace ErsharpClient
  2.  
  3. open System
  4. open Otp
  5.  
  6. module Main =
  7.  
  8. let (|Atom|_|) text (term : Erlang.Object) =
  9. match term with
  10. | :? Erlang.Tuple as tuple ->
  11. let terms = tuple.elements()
  12. if terms.Length <> 2 then
  13. None
  14. else match terms.[0] with
  15. | :? Erlang.Atom as atom ->
  16. if atom.atomValue() = text then Some(terms.[1])
  17. else None
  18. | _ -> None
  19. | _ -> None
  20.  
  21. let ConnectTo serverNode cookie =
  22. let clientNode = new OtpSelf("clientnode", cookie)
  23. let serverNode = new OtpPeer(serverNode)
  24. clientNode.connect(serverNode)
  25.  
  26. let StartGenServer (connection : OtpConnection) =
  27. connection.sendRPC("mathserver", "start_link", Array.empty<Otp.Erlang.Object>)
  28. let start = connection.receiveRPC()
  29. match start with
  30. | Atom "ok" pid -> pid
  31. | Atom "error" value ->
  32. match value with
  33. | Atom "already_started" pid2 -> pid2
  34. | _ -> raise (new System.InvalidOperationException(start.ToString()))
  35. | _ -> raise (new System.InvalidOperationException(start.ToString()))
  36.  
  37.  
  38. [<EntryPoint>]
  39. let Main arguments =
  40. let connection = ConnectTo "servernode@YourNodeNameHere" "cookie"
  41. let pid = StartGenServer connection
  42.  
  43. let args = [| new Otp.Erlang.Long(6L); new Otp.Erlang.Long(9L)|] : Otp.Erlang.Object array
  44. connection.sendRPC("mathserver", "multiply", args);
  45. let result = connection.receiveRPC()
  46.  
  47. match result with
  48. | Atom "ok" value -> Console.WriteLine("Return Value:" + value.ToString())
  49. | _ -> Console.WriteLine("Failure:" + result.ToString())
  50.  
  51. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement