Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6647203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:30:35+00:00 2026-05-26T00:30:35+00:00

I intend to build on this code, found here However, I notice I can

  • 0

I intend to build on this code, found here
However, I notice I can telnet to this server on the local host. Can’t from another computer. I did a quick nmap scan, which reported that nothing was listening on the port I had selected.
For purposes of troubleshooting, I had shut down my firewall, so I’ve ruled that out as a possible problem.

Clues from haskell windows programmers would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:30:35+00:00Added an answer on May 26, 2026 at 12:30 am

    This is for future new haskellers.
    I based my code on this example.
    I made improvements based on this reddit thread, and suggestions made above. The import statements are still sloppy, but fixing them is left as the proverbial “exercise for the reader”. I invite any additional suggestions leading to improvements.

    import Network.Socket
    import Control.Monad
    import Network
    import System.Environment (getArgs)
    import System.IO
    import Control.Concurrent (forkIO)
    
    main :: IO ()
    main = withSocketsDo $ do
       [portStr] <- getArgs
       sock <- socket AF_INET Stream defaultProtocol 
       let port = fromIntegral (read portStr :: Int)
           socketAddress = SockAddrInet port 0000 
       bindSocket sock socketAddress
       listen sock 1
       putStrLn $ "Listening on " ++ (show port)
       sockHandler sock
    
    sockHandler :: Socket -> IO ()
    sockHandler sock' = forever $ do
        (sock, _) <- Network.Socket.accept sock'
        handle <- socketToHandle sock ReadWriteMode
        hSetBuffering handle NoBuffering
        forkIO $ commandProcessor handle
    
    commandProcessor :: Handle -> IO ()
    commandProcessor  handle = forever $ do
        line <- hGetLine handle
        let (cmd:arg) = words line
        case cmd of
            "echo" -> echoCommand handle arg 
            "add" -> addCommand handle arg 
            _ -> do hPutStrLn handle "Unknown command"
    
    echoCommand :: Handle -> [String] -> IO ()
    echoCommand handle arg = do
        hPutStrLn handle (unwords arg)
    
    addCommand :: Handle -> [String] -> IO ()  
    addCommand handle [x,y] = do
        hPutStrLn handle $ show $ read x + read y
    addCommand handle _ = do
        hPutStrLn handle "usage: add Int Int"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to upgrade our build server at work, going from having no
I intend to build a web application where users can enter their time every
I want to send a broadcast from my widget with this code: for (int
I have found various topics here and elsewhere on creating an intent for sending
Can someone help me with this issue? I currently working on my project for
I intend to build a small web site that will poll a third party
So, what I'm actually looking for is this solution: Get/pick an image from Android's
I am using this code to allow the user to log in to facebook
I'm building (well, trying to build) a simple usenet news reader. The code below
How to open an URL from code in the built-in web browser rather than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.