Last active
March 11, 2017 20:03
-
-
Save 17cupsofcoffee/30ec620ed02b69a0cf696b50a6c04f81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Net | |
open Akka.FSharp | |
open Akka.IO | |
open Akka.Actor | |
let system = System.create "system" (Configuration.defaultConfig()) | |
type GreeterMsg = | |
| Hello of string | |
| Goodbye of string | |
let greeter = spawn system "greeter" <| fun mailbox -> | |
let rec loop() = actor { | |
let! msg = mailbox.Receive() | |
match msg with | |
| Hello name -> printf "Hello, %s!\n" name | |
| Goodbye name -> printf "Goodbye, %s!\n" name | |
return! loop() | |
} | |
loop() | |
let server = spawn system "server" <| fun (mailbox: Actor<obj>) -> | |
let rec loop() = actor { | |
let! msg = mailbox.Receive() | |
match msg with | |
| :? Tcp.Bound as bound -> | |
printf "Listening on %O\n" bound.LocalAddress | |
| _ -> mailbox.Unhandled() | |
return! loop() | |
} | |
mailbox.Context.System.Tcp() <! Tcp.Bind(mailbox.Self, IPEndPoint(IPAddress.Any, 9090)) | |
loop() | |
System.Console.ReadLine() |> ignore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment