net001.hs 644 Bytes
Newer Older
1
2
3
4
5
6
module Main where

import Socket
import Concurrent
import IO

sof's avatar
sof committed
7
8
9
10
11
12
13
14
-- NOTE: this test depends on non-blocking I/O support,
-- which win32 doesn't support. Rather than having the
-- test program block, we fail to initialise WinSock
-- (via withSocketsDo) here so that the test will fall over
-- (and repeatedly remind us to implement Win32 support
-- for non-blocking I/O !)

main = {- withSocketsDo $ -} do
15
16
17
18
19
20
21
22
23
24
25
26
27
   forkIO server
   yield
   h <- connectTo "localhost" (PortNumber 22222)
   l <- hGetLine h
   hClose h
   print l
 where
   server = do
	  s <- listenOn (PortNumber 22222)
	  (h, host, port) <- accept s
	  hPutStrLn h "hello"
	  hClose h