<commit_before>{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Exception      (bracket)
import Control.Monad.IO.Class (liftIO)
import Data.Function          ((&))
import Network.Simple.TCP     (connectSock)
import Network.Socket         (socketToHandle)
import System.Exit            (exitSuccess)
import System.IO              (IOMode(ReadWriteMode), hClose)

import Data.Capnp        (def, defaultLimit)
import Network.RPC.Capnp (bootstrap, handleTransport, runVat)

import Capnp.Echo.Pure

main = bracket openConn hClose talk
  where
    openConn = do
        (sock, _addr) <- connectSock "localhost" "4000"
        socketToHandle sock ReadWriteMode
    talk handle =
        runVat def (handleTransport defaultLimit handle) $ do
            echoSrv <- Echo <$> bootstrap
            result <- echoSrv & echo'echo def { query = "Hello, World!" }
            liftIO $ do
                print result
                exitSuccess<commit_msg>Use socketTransport in the echo client example.<commit_after>{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad.IO.Class (liftIO)
import Data.Function          ((&))
import Network.Simple.TCP     (connect)
import System.Exit            (exitSuccess)
import System.IO              (IOMode(ReadWriteMode), hClose)

import Data.Capnp        (def, defaultLimit)
import Network.RPC.Capnp (bootstrap, runVat, socketTransport)

import Capnp.Echo.Pure

main = connect "localhost" "4000" $ \(sock, _addr) -> do
    transport <- socketTransport defaultLimit sock
    runVat def transport $ do
        echoSrv <- Echo <$> bootstrap
        result <- echoSrv & echo'echo def { query = "Hello, World!" }
        liftIO $ do
            print result
            exitSuccess
{'fraction_non_alphanumeric': 0.09226361031518625, 'fraction_numerical': 0.004584527220630372, 'mean_word_length': 2.6224066390041494, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2921490', 'n_tokens_mistral': 506, 'n_tokens_neox': 483, 'n_words': 144}