-- Requests consist of serializable header and an optional bytestring message
let request = Message (42 :: Int) (Just "some-additional-data")
-- Start a server which responds to `x` with `x + 1`
tid <-
  forkIO
    ( void
        ( TcpMsg.run @Int @Int -- Request and response types
            ( ServerSettings
                { tcpOpts = ServerTcpSettings {port = 44551},
                  action = \(Message x bytes) -> return (Message (x + 1) bytes) -- Server processes requests in parallel
                }
            )
        )
    )
threadDelay 1000 -- wait for the server to start
-- Start a client which sends a single request
let clientOpts = ClientOpts {serverHost = "localhost", serverPort = 44551}
client <- createClient clientOpts
response <- (client `ask` request >>= wait) -- `ask` performs a non-blocking request
response `shouldBe` Message (43 :: Int) (Just "some-additional-data")- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Low overhead request-response framework for Haskell applications
License
MaciejWas/tcp-messenger
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
Low overhead request-response framework for Haskell applications
Topics
Resources
License
Stars
Watchers
Forks
Releases
No releases published
              Packages 0
        No packages published