-
Notifications
You must be signed in to change notification settings - Fork 5
/
HttpServer.hs
29 lines (28 loc) · 1.15 KB
/
HttpServer.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module HttpServer where
import Network
import Control.Concurrent
import System.IO
--
--responseMessage = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nPong!\r\n"
--port = 1981 :: PortNumber
--
--myServer = withSocketsDo $ do
-- socket <- createSocket port
-- print ("Server running in port " ++ show port)
-- service socket
--
--service :: Socket -> IO()
--service socket = do
-- (handler,hostname,portNumber) <- accept socket -- Accept a connection on a socket created by 'listenOn'
-- print ("Request received by hostname " ++ hostname)
-- forkIO $ createResponse handler -- Running response in a new thread
-- service socket --Recursive call to subscribe again for new request
--
--createSocket :: PortNumber -> IO Socket
--createSocket port = listenOn $ PortNumber port -- $ means like use parenthesis listenOn(PortNumber 5002)
--
--createResponse :: Handle -> IO ()
--createResponse handler = do
-- hPutStr handler responseMessage -- Write the response in output buffer.
-- hFlush handler -- Sent data in buffer immediately to the operating system.
-- hClose handler -- Close handler.