{-|
  Module     : Main
  Copyright  : Copyright (C) 2010 https://github.com/berufsnerd
  License    : GPLv3

  Portability: non-portable
  
  The main module for the example haskell tcp server, a training
  excecise to learn something about socket inter-process communication.
-}
module Main where

import System.IO.Error
import System.Log.Logger
import Network

import Server

main = withSocketsDo $ do
  mapM_ (flip updateGlobalLogger (setLevel DEBUG))
    [log, "Server", "Client"]

  startServer serverPort `catch`
    (\msg -> errorM log $ failedStartMsg serverPort msg)
  where 
    log                     = "Main"
    serverPort              = 2252 -- 2252 is CALC on telefone keyboards
    failedStartMsg port err = "Unable to start the server. " ++ 
      "Maybe another process is using port tcp/" ++ show port ++ ". " ++
      "(Error: " ++ ioeGetErrorString err ++ ")"
