content: {-# LANGUAGE OverloadedStrings #-}
  
  module Main (main) where
  
  import Control.Monad (forever)
  import qualified Data.ByteString.Char8 as BC
  import Network.Socket
  import System.IO (BufferMode (NoBuffering), hSetBuffering, stdout, stderr)
  
  main :: IO ()
  main = do
      -- Disable output buffering
      hSetBuffering stdout NoBuffering
      hSetBuffering stderr NoBuffering
  
      let host = "127.0.0.1"
          port = "4221"
  
      BC.putStrLn $ "Listening on " <> BC.pack host <> ":" <> BC.pack port
  
      -- Get address information for the given host and port
      addrInfo <- getAddrInfo Nothing (Just host) (Just port)
  
      serverSocket <- socket (addrFamily $ head addrInfo) Stream defaultProtocol
      bind serverSocket $ addrAddress $ head addrInfo
      listen serverSocket 5
  
      -- Accept connections and handle them forever
      forever $ do
          (clientSocket, clientAddr) <- accept serverSocket
          BC.putStrLn $ "Accepted connection from " <> BC.pack (show clientAddr) <> "."
          -- Handle the clientSocket as needed...
  
          close clientSocket
  