Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write a minimal-overhead proxy to localhost:3389 in Haskell?
    text
    copied!<p><strong>Update: question now contains the final edited answer!</strong></p> <p>I now use the following (final answer):</p> <pre><code>module Main where import Control.Concurrent (forkIO) import Control.Monad (when,forever,void) import Network (PortID(PortNumber),listenOn) import Network.Socket hiding (listen,recv,send) import Network.Socket.ByteString (recv,sendAll) import qualified Data.ByteString as B import System type Host = String type Port = PortNumber main :: IO () main = do [lp,h,p] &lt;- getArgs start (port lp) h (port p) where port = fromInteger . read start :: Port -&gt; Host -&gt; Port -&gt; IO () start lp rh rp = withSocketsDo $ do proxy &lt;- listenOn $ PortNumber lp forever $ do (client,_) &lt;- accept proxy void . forkIO $ (client &gt;-&lt;) =&lt;&lt; rh .@. rp (.@.) :: Host -&gt; Port -&gt; IO Socket host .@. port = do addr:_ &lt;- getAddrInfo Nothing (Just host) (Just $ show port) server &lt;- socket (addrFamily addr) Stream defaultProtocol connect server (addrAddress addr) return server (&gt;-&lt;) :: Socket -&gt; Socket -&gt; IO () x &gt;-&lt; y = do x &gt;- y; y &gt;- x (&gt;-) :: Socket -&gt; Socket -&gt; IO () s &gt;- r = void . forkIO . handle $ forever stream where stream = recv s (64 * 1024) &gt;&gt;= ifNot0 &gt;&gt;= sendAll r ifNot0 = \c -&gt; do when (B.null c) $ handle (error "0"); return c handle = flip catch $ \e -&gt; print e &gt;&gt; sClose s &gt;&gt; sClose r </code></pre> <p>which can be run like this:</p> <pre><code>proxy 2000 localhost 3389 </code></pre> <p>Using mRemote, if I connect to localhost:2000, I <strong>do</strong> see the login screen of the local machine! :)</p> <p>*If I find a way to improve <code>(&gt;-)</code> even further, I will update this answer!</p>
 

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