Skip to content

Instantly share code, notes, and snippets.

@keizo042
Last active August 28, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keizo042/668d9eed536922218e389dd99018d0df to your computer and use it in GitHub Desktop.
Save keizo042/668d9eed536922218e389dd99018d0df to your computer and use it in GitHub Desktop.
newManager :: ManagerSetting -> IO Manager
newManager = undefined
open :: Manager -> String -> Int -> IO Context
open = undefined
connect :: Context -> IO ()
connect = undefined
send :: Context -> Bytestring -> IO ()
send = undefined
recv :: Context -> IO ByteString
recv = undefined
client = do
mgr <- newManager defaultManager
ctx <- open mgr "localhost" 8080
conenct ctx -- Send Client Initial with TLS Client Hello
send ctx "hello world" -- Stream Frame
bs <- recv ctx -- now, it wait forever
putStrLn bs
close ctx -- send Connection Close Frame
closeManager mgr
bind :: Manager -> String -> Port -> Context
bind = undefined
listen :: Manager -> IO Context
listen = undefined.
server = do
mgr <- newManager defaultManager
bind mgr "loclhost" 8080 -- manager behaves as Server mode.
ctx <- listen mgr -- get Connection Context.
server' ctx
server
where
server' Context -> IO ThreadId
server' ctx = forkIO $ do
when (contextFinished ctx) return () -- already recv Connection Close Frame
bs <- recv ctx -- recv Stream from client
send ctx ("pong:" ++ bs) -- send Stream Frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment