Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重新连接web套接字[Haskell]_Haskell_Websocket - Fatal编程技术网

重新连接web套接字[Haskell]

重新连接web套接字[Haskell],haskell,websocket,Haskell,Websocket,我正在使用wuss库(围绕websockets的包装器)创建websocket连接。如果web套接字因任何原因断开连接,如何创建重新连接的循环 ws :: ClientApp () ws connection = do putStrLn "Connected!" sendTextData connection msgSubscribe -- defined elsewhere let loop = do message <- receiveDa

我正在使用
wuss
库(围绕
websockets
的包装器)创建websocket连接。如果web套接字因任何原因断开连接,如何创建重新连接的循环

ws :: ClientApp ()
ws connection = do
    putStrLn "Connected!"

    sendTextData connection msgSubscribe -- defined elsewhere

    let loop = do 
        message <- receiveData connection
        print (message)
        loop

    loop
    sendClose connection (pack "Bye!")

main :: IO ()
main = runSecureClient "ws.kraken.com" 443 "/" ws -- retry at this point?
ws::ClientApp()
ws-connection=do
putStrLn“已连接!”
sendTextData连接msgSubscribe--在别处定义
让循环=做
消息如何“重试”取决于协议。如果你真的只想在连接失败时从头开始重试,你可以这样做

{-# LANGUAGE ScopedTypeVariables #-}
import Control.Exception (catch)

-- ...
-- the rest of your code
-- ...

retryOnFailure ws = runSecureClient "ws.kraken.com" 443 "/" ws
  `catch` (\e -> 
     if e == ConnectionClosed
     then retryOnFailure ws
     else return ())
但请注意,这是一次“愚蠢”的重试,因为如果远程连接意外关闭(预期的关闭将导致程序结束),它将从头开始。如果您想保持任何类型的状态或类似的状态,您必须找出如何为您遵循的任何协议执行该操作,但如果您只是通过某个脆弱的连接侦听数据,这就足够了