Skip to content

Instantly share code, notes, and snippets.

@17cupsofcoffee
Last active March 11, 2017 20:03
Show Gist options
  • Save 17cupsofcoffee/30ec620ed02b69a0cf696b50a6c04f81 to your computer and use it in GitHub Desktop.
Save 17cupsofcoffee/30ec620ed02b69a0cf696b50a6c04f81 to your computer and use it in GitHub Desktop.
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