Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/totbwf/socks.fs
A functional socket library for F#
https://github.com/totbwf/socks.fs
fsharp socket
Last synced: 19 days ago
JSON representation
A functional socket library for F#
- Host: GitHub
- URL: https://github.com/totbwf/socks.fs
- Owner: TOTBWF
- License: mit
- Created: 2017-07-28T01:19:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-28T22:04:25.000Z (over 7 years ago)
- Last Synced: 2024-11-16T09:34:33.543Z (3 months ago)
- Topics: fsharp, socket
- Language: F#
- Size: 11.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Socks.fs
A functional socket library for F#Socks is a library for F# that provides a simple, safe, and composable method for socket programming.
## Getting Started
First, install and build the library
```sh
cd src
dotnet restore
dotnet build
```Now all we have to do is use the `socketIO` computation expression and we are off to the races!
Notice how all of the socket computation is being run asynchrounously!```fsharp
let socketExample = socketIO {
do! Socket.writeSocket "What is your name?"
let! name = Socket.readSocket
do! Socke.twriteSocket ("Hello " + name)
}
Socket.run 9000 socketExample |> Async.Start
```These small snippets can be composed as well!
```fsharp
let socketExample = socketIO {
do! Socket.writeSocket "What is your name?"
return! Socket.readSocket
}let socketComposed = socketIO {
let! name = Socket.socketExample
do! Socket.writeSocket("Your name is " + name)
}Socket.run 9000 socketComposed |> Async.Start
```There is also the option to run the same computation with multiple connections:
```fsharp
let socketExample = socketIO {
do! Socket.writeSocket "What is your name?"
let! name = Socket.readSocket
do! Socket.writeSocket ("Hello " + name)
}
Async.Start(Socket.runParallel 9000 100 socketExample)
```