Socket library ghc 5.02.1
Sven Eric Panitz
sep@softwareag.com
Tue, 27 Nov 2001 13:46:24 +0100
From: "Sigbjorn Finne" <sof@galconn.com>
Cc: <glasgow-haskell-users@haskell.org>
References: <200111220959.KAA29614@softwareag.com>
Date: Mon, 26 Nov 2001 12:30:47 -0800
"Sven Eric Panitz" <sep@softwareag.com> writes:
>
> It seems that the Socket library does still not work
> with ghc 5.02.1.
> I tried the simple test:
>
> > main =
> > do
> > d <- connectTo "localhost" (PortNumber 80)
> > hPutStr d "GET / HTTP/1.0\n\n"
> > hFlush d
> > c <- hGetContents d
> > putStr c
>
> On Windows2000 I get the known error:
>
> *** Exception: does not exist
> Action: getProtocolByName
> Reason: no such protocol entry
>
(You, of course, need to wrap up that code with Socket.withSocketDo
to start up WinSock first).
FYI, in case you're planning on doing socket programming with GHC-5.02
on a Win32 platform, stay away from using the higher-level Socket module,
since its IO.Handle based view of sockets is just broken. Stick with the
lower-level SocketPrim interface instead.
Specifically, stay away from using the following:
* Socket. connectTo
* Socket.accept
* Socket.sendTo
* Socket. recvFrom
* SocketPrim.socketToHandle
--sigbjorn
Thanks for the help and valuable information.
I tried the following little test, which stays away from
above functions:
> module Main where
>
> import BSD
> import SocketPrim
> import Socket (withSocketsDo)
>
> main =
> Socket.withSocketsDo
> (do
> protNum <- getProtocolNumber "tcp"
> s <- socket AF_INET Stream protNum
> hostAddr <- inet_addr "157.189.164.68"
> let sAddr = (SockAddrInet (toEnum 8080) hostAddr)
> connect s sAddr
> i <- sendTo s "GET / HTTP/1.0\r\n\r\n" sAddr
> (str,l,imsAddr) <- recvFrom s 1000
> putStr str
> )
But something I seem to be doing wrong.
During evaluation of 'recvFrom s 1000' I get the following
error message (consistently for unix and windows):
Fail: SocketPrim.hsc:241: Non-exhaustive patterns in case
As the log of the webserver reveals the sendTo works fine.
Any idea what could be my problem?
Sven Eric