server.icl 780 Bytes
Newer Older
1 2 3 4 5 6 7 8
module server

import StdDebug

import StdEnv
import Data.Error
import Data.Maybe
import System.Socket
9
import System.Socket.Ipv4
10 11 12

Start :: *World -> (MaybeOSError (), *World)
Start w
Mart Lubbers's avatar
Mart Lubbers committed
13
	= case socket SocketStream w of
14 15
		(Error e, w) = (Error e, w)
		(Ok sockfd, w)
Mart Lubbers's avatar
Mart Lubbers committed
16
			#! (merr, sockfd) = bind {ipv4_socket_port=8124,ipv4_socket_addr=Nothing} sockfd
17
			| isError merr = (merr, w)
18
			#! (merr, sockfd) = listen 3 sockfd
19 20 21 22
			| isError merr = (merr, w)
			= case accept sockfd of
				(Error e, sockfd) = (Error e, w)
				(Ok (sock, addr), sockfd)
Mart Lubbers's avatar
Mart Lubbers committed
23
					# (merr, sock) = send "Hello world!" [] sock
24
					| isError merr = (liftError merr, w)
25 26 27 28 29
					# (merr, w) = close sock w
					| isError merr = (merr, w)
					# (merr, w) = close sockfd w
					| isError merr = (merr, w)
					= (Ok (), w)