Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Found <a href="https://gist.github.com/738025" rel="nofollow">this gist</a> a few months ago when I was getting started with Haskell.</p> <p>It's really simple and easy to understand.</p> <p><strong>EDIT</strong>: Based on the gist above, here is a tested RDP proxy. Difference is replacing <code>send</code> with <code>sendAll</code> to make sure all data is delivered. Found this problem when testing through the linux rdp server (large payload disconnects).</p> <pre><code>module Main where import Control.Concurrent (forkIO) import Control.Monad (forever,unless) import Network (PortID(PortNumber),listenOn) import qualified Data.ByteString as S import Network.Socket hiding (listen,recv,send) import Network.Socket.ByteString (recv,sendAll) import System.Posix (Handler(Ignore),installHandler,sigPIPE) localPort :: PortNumber localPort = 3390 remoteHost :: String remoteHost = "localhost" remotePort :: Integer remotePort = 3389 main :: IO () main = do ignore $ installHandler sigPIPE Ignore Nothing start start :: IO () start = withSocketsDo $ do listener &lt;- listenOn $ PortNumber localPort forever $ do (client,_) &lt;- accept listener ignore $ forkIO $ do server &lt;- connectToServer client `proxyTo` server server `proxyTo` client return () where connectToServer = do addrinfos &lt;- getAddrInfo Nothing (Just remoteHost) (Just $ show remotePort) let serveraddr = head addrinfos server &lt;- socket (addrFamily serveraddr) Stream defaultProtocol connect server (addrAddress serveraddr) return server proxyTo from to = do ignore $ forkIO $ flip catch (close from to) $ forever $ do content &lt;- recv from 1024 unless (S.null content) $ sendAll to content return () close a b _ = do sClose a sClose b -- | Run an action and ignore the result. ignore :: Monad m =&gt; m a -&gt; m () ignore m = m &gt;&gt; return () </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload