Question

I've written a simple Hello World application for (Warp) on (Wai). It works fine in Ubuntu Linux, as do more complicated apps. But I can't even get this Hello World app to run in Windows. I'm using Haskell Platform (installation file 2012.2.0.0) on Windows 7 Home Premium SP1 32-bit.

This is the code (which works in Linux):

{-# LANGUAGE OverloadedStrings #-} 

import Network
import Network.Wai
import Network.HTTP.Types (status200)
import Network.Wai.Handler.Warp (run)
-------------------------------------------------------------------------------
application = \_-> return $ responseLBS status200 [("Content-Type", "text/plain")] 
                            "Hello World" 

main = withSocketsDo $ do run 3000 application

These are the GHCI messages upon loading the code, and running (main):

Prelude> :l wai_hello_world.hs
[1 of 1] Compiling Main             ( wai_hello_world.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package [ **edited**: blah blah blah - other packages - removed for readability]
Loading package warp-1.3.2 ... linking ... done.

After loading the code, the web server does not appear to be running.

I think I might be running into some common gotcha - if so please let me know.

Thanks in advance for all feedback.

(Update: as noted in an answer below, these errors are solely due to the Ctrl-C action, killing the runtime, and not part of the unexpected behaviour of Wai/Warp in the question.)

If I hit Ctrl-C a few times to break out, I get these messages, or some variety of them:

NIenttweorrrku.pStoecdk.e
t.ace*Main> p: failed (No error)
user error (accept: can't perform accept on socket ((AF_INET,Stream,0)) in status Closed)
user error (accept: can't perform accept on socket ((AF_INET,Stream,0)) in status Closed)
*Main>
*Main> user error (accept: can't perform accept on socket ((AF_INE,:Sream,0)) in status Closed)
q
Leaving GHCi.
Était-ce utile?

La solution

You probably need to use withSocketsDo.

Autres conseils

This fixed the problem (and I do feel silly):

  1. Tore down the stack, uninstalled Haskell Platform 2012.2.0.0 for Windows.
  2. Installed the latest Haskell Platform 2012.4.0.0 for Windows.
  3. Installed the package/libraries (cabal install yesod-platform).
  4. Approved the Windows Firewall query on GHC, when the code was run.
  5. Code now runs as expected. I now have no problem. Perhaps it was the firewall. :-S
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top