Stream Vs Handle,respondHTTP抛出错误

时间:2015-07-05 10:42:25

标签: sockets haskell stream

Network.accept返回一个关于接受连接的句柄,我将其作为参数传递给respondHTTP(来自Network.HTTP.Base) 他们的类型是,

accept :: Socket -> IO (Handle, HostName, PortNumber)
respondHTTP :: HStream ty => HandleStream ty -> Response ty -> IO ()

这一行 - git-code

handleResponse = Kleisli (print ||| respondHTTP c)

,抛出错误,

simpleserver.hs:43:53:
    Couldn't match expected type ‘Network.TCP.HandleStream ty’
                with actual type ‘Handle’
    Relevant bindings include
      handleResponse :: Kleisli IO (Either b (Response ty)) ()
        (bound at simpleserver.hs:43:5)
    In the first argument of ‘respondHTTP’, namely ‘c’
    In the second argument of ‘(|||)’, namely ‘respondHTTP c’

在将Handle传递给Network.accept)之前,如何将Stream(从respondHTTP返回到<?php $imgfile = fopen(image/location.jpg); $loadimg = imagecreatefromjpeg($imgfile); imagejpeg($loadimg); ?>

1 个答案:

答案 0 :(得分:1)

来自||的{​​{1}}和来自HandleStream的{​​{1}}是两件不同的事情;没有超类 - 子类关系。它们不可互换。

创建Network.TCP,然后将其传递给socketConnection,而不是Handle。这将返回您需要的System.IO