Last active
August 28, 2017 13:29
-
-
Save keizo042/668d9eed536922218e389dd99018d0df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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