Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
berndlosert committed Dec 12, 2023
1 parent a0fc6e6 commit fa86381
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
35 changes: 3 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ rm -rf /usr/local/share/emacs/site-lisp/agda
Save the following code into a file called `hello.agda`.

```agda
{-# OPTIONS --guardedness #-}
open import Prelude
open import System.IO
Expand All @@ -85,38 +87,7 @@ agda --compile hello.agda

Save the following code into a file called `echo-server.agda`:

```agda
{-# OPTIONS --guardedness #-}
open import Prelude
open import Data.Bytes as Bytes using ()
open import Data.List as List using ()
open import Data.String.Encoding
open import Network.Socket
open import System.IO
runTCPEchoServer : IO Unit
runTCPEchoServer = do
(serverAddr , _) <- getAddrInfo nothing (just "127.0.0.1") (just "7000")
serverSocket <- socket (addrFamily serverAddr) sockStream defaultProtocol
setSocketOption serverSocket reuseAddr 1
bind serverSocket (addrAddress serverAddr)
listen serverSocket 1
(clientSocket , _) <- accept serverSocket
print {String} "Waiting for a message..."
message <- recv clientSocket 1024
unless (Bytes.null message) do
print ("Received: " <> decodeUtf8 message)
print {String} "Echoing..."
sendAll clientSocket message
print {String} "Closing..."
close clientSocket
close serverSocket
main : IO Unit
main = runTCPEchoServer
```
https://github.com/berndlosert/agda-base/blob/master/examples/echo-server.agda#L1-L30

Compile this code by running `agda --compile echo-server.agda`. If you get the
following errors:
Expand Down
2 changes: 2 additions & 0 deletions examples/echo-server.agda
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS --guardedness #-}

open import Prelude

open import Data.Bytes as Bytes using ()
Expand Down

0 comments on commit fa86381

Please sign in to comment.