Created
December 14, 2016 19:01
-
-
Save bryanhunter/4e5429778459ad59959678accbe2b172 to your computer and use it in GitHub Desktop.
F# script that connects to Phoenix channels
This file contains 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
// This sample shows connecting to a sample Phoenix chat application running locally. | |
// The sample Phoenix app was written by Chris McCord and can be found here: | |
// https://github.com/chrismccord/phoenix_chat_example) | |
// #r @".\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll" | |
open WebSocketSharp | |
let ws = new WebSocket("ws://localhost:4000/socket/websocket") | |
ws.OnOpen.Add(fun args -> System.Console.WriteLine("Open")) | |
ws.OnClose.Add(fun args -> System.Console.WriteLine("Close")) | |
ws.OnMessage.Add(fun args -> System.Console.WriteLine("Msg: {0}", args.Data)) | |
ws.OnError.Add(fun args -> System.Console.WriteLine("Error: {0}", args.Message)) | |
ws.Connect() | |
ws.Send("""{"ref":"1", "event":"phx_join", "topic":"rooms:lobby", "payload":{"user":"boo"}}""") | |
ws.Send("""{"ref":"2", "event":"new:msg", "topic":"rooms:lobby", "payload":{"user":"boo","body":"howdy"}}""") | |
ws.Send("""{"ref":"3", "event":"new:msg", "topic":"rooms:lobby", "payload":{"user":"boo","body":"Woohoo!"}}""") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment