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 7876923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:14:43+00:00 2026-06-03T03:14:43+00:00

I asked a question about signal on windows with the same code,here is another

  • 0

I asked a question about signal on windows with the same code,here is another question

import IO
import Control.Exception hiding (catch)
import Control.Concurrent
import Network

main = withSocketsDo $ do {main'}
main' = listenOn (PortNumber 9900) >>= acceptConnections

acceptConnections sock = do
        putStrLn $ "trying to accept" ++ (show sock)-- debug msg
        conn@(h,host,port) <- accept sock
        print conn -- debug msg
        forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
        acceptConnections sock

talk conn@(h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn

I run the program on win7,and it looks like the socket created succeed,but I can’t telnet on,and netstat doesn’t show any listening socket with the process,is there anything wrong?Or,haskell has bug on windows?(By the way,on debian with this code works perfect)

  • 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-06-03T03:14:44+00:00Added an answer on June 3, 2026 at 3:14 am

    when I use netstat -a on win7,I found the listening ip with port 9900 is [::],neither is 127.0.0.1 nor 0.0.0.0,so I guess the problem is during create socket in function “listenOn”,then I wrote “listenOn2” replaced.And the problem is solved.
    Here is the full code:(the only difference is change the proto from [[getProtocolNumber “tcp”]] to [[defaultProtocol]]),maybe this is a bug.

    import IO
    import Control.Exception hiding (catch)
    import Control.Concurrent
    import Network
    import Network.Socket
    listenOn2 (PortNumber port) = do
            --proto <- getProtocolNumber "tcp"  ,here is the difference!!!!
            let proto = defaultProtocol
            bracketOnError
                (socket AF_INET Stream proto)
                (sClose)
                (\sock -> do
                    setSocketOption sock ReuseAddr 1
                    --addr <- inet_addr "127.0.0.1"
                    bindSocket sock (SockAddrInet port iNADDR_ANY)
                    listen sock maxListenQueue
                    return sock
                )
    main = withSocketsDo $ do {main'}
    main' = listenOn2 (PortNumber 9900) >>= acceptConnections
    
    acceptConnections sock = do
            putStrLn $ "trying to accept" ++ (show sock)-- debug msg
            conn@(h,host,port) <- Network.accept sock
            print conn -- debug msg
            forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
            acceptConnections sock
    
    talk conn@(h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked a question about same code but got lost in translation Here's what
I asked another question about custom AlertDialog here . Then I clicked my way
I recently asked a question about formatting JavaScript code in Vim. And I've also
I asked this question about a year ago on another site but never got
I asked a question about this that was originally answered here . Originally, I
I asked a question about this that was specific to my code and people
I asked another question about HTML and PHP separation as I have seen references
I asked a question about callbacks and arrived at another question (see comment). How
Just asked a question about linking Boost libraries in the make file. Thanks to
I asked a question about building custom Thread Safe Generic List now I am

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.