@@ -68,6 +68,8 @@ rm -rf /usr/local/share/emacs/site-lisp/agda
68
68
Save the following code into a file called ` hello.agda ` .
69
69
70
70
``` agda
71
+ {-# OPTIONS --guardedness #-}
72
+
71
73
open import Prelude
72
74
open import System.IO
73
75
@@ -85,38 +87,7 @@ agda --compile hello.agda
85
87
86
88
Save the following code into a file called ` echo-server.agda ` :
87
89
88
- ``` agda
89
- {-# OPTIONS --guardedness #-}
90
-
91
- open import Prelude
92
-
93
- open import Data.Bytes as Bytes using ()
94
- open import Data.List as List using ()
95
- open import Data.String.Encoding
96
- open import Network.Socket
97
- open import System.IO
98
-
99
- runTCPEchoServer : IO Unit
100
- runTCPEchoServer = do
101
- (serverAddr , _) <- getAddrInfo nothing (just "127.0.0.1") (just "7000")
102
- serverSocket <- socket (addrFamily serverAddr) sockStream defaultProtocol
103
- setSocketOption serverSocket reuseAddr 1
104
- bind serverSocket (addrAddress serverAddr)
105
- listen serverSocket 1
106
- (clientSocket , _) <- accept serverSocket
107
- print {String} "Waiting for a message..."
108
- message <- recv clientSocket 1024
109
- unless (Bytes.null message) do
110
- print ("Received: " <> decodeUtf8 message)
111
- print {String} "Echoing..."
112
- sendAll clientSocket message
113
- print {String} "Closing..."
114
- close clientSocket
115
- close serverSocket
116
-
117
- main : IO Unit
118
- main = runTCPEchoServer
119
- ```
90
+ https://github.com/berndlosert/agda-base/blob/master/examples/echo-server.agda#L1-L30
120
91
121
92
Compile this code by running ` agda --compile echo-server.agda ` . If you get the
122
93
following errors:
0 commit comments