windows network programming

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

windows network programming

Michael Litchard
I took a quick look on hackage for an interface to windows networking
function calls, and didn't find anything that worked. I may have
overlooked something. What's the state of windows network programming?
Any recommendations for a good package?
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Antoine Latter-2

Have you tried the 'network' package on Hackage? I had thought it was cross-platform. I do not do much development on Windows.

On Nov 1, 2010 6:45 PM, "Michael Litchard" <[hidden email]> wrote:
> I took a quick look on hackage for an interface to windows networking
> function calls, and didn't find anything that worked. I may have
> overlooked something. What's the state of windows network programming?
> Any recommendations for a good package?
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Paulo Tanimoto-4
On Mon, Nov 1, 2010 at 7:04 PM, Antoine Latter <[hidden email]> wrote:
> Have you tried the 'network' package on Hackage? I had thought it was
> cross-platform. I do not do much development on Windows.
>
> On Nov 1, 2010 6:45 PM, "Michael Litchard" <[hidden email]> wrote:
>> I took a quick look on hackage for an interface to windows networking
>> function calls, and didn't find anything that worked. I may have
>> overlooked something. What's the state of windows network programming?
>> Any recommendations for a good package?

Yes, I think it is cross-platform and it ships with Haskell Platform
(so you don't have to compile by yourself).

http://hackage.haskell.org/platform/contents.html

Michael, also note that the newest version on Hackage merges "network"
and "network-bytestring".

http://hackage.haskell.org/package/network

Paulo
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Nils Schweinsberg
Am 02.11.2010 01:20, schrieb Paulo Tanimoto:
> http://hackage.haskell.org/package/network

You just have to remember that you need to call "withSocketsDo" on
windows before doing anything with the network library.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Michael Litchard
got any urls with examples?

On Tue, Nov 2, 2010 at 12:17 AM, Nils Schweinsberg <[hidden email]> wrote:

> Am 02.11.2010 01:20, schrieb Paulo Tanimoto:
>>
>> http://hackage.haskell.org/package/network
>
> You just have to remember that you need to call "withSocketsDo" on windows
> before doing anything with the network library.
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Nils Schweinsberg
Am 02.11.2010 19:57, schrieb Michael Litchard:
> got any urls with examples?

Sure, see this short server-client-ping-pong application.

By the way, I noticed that you don't need withSocketsDo on windows 7,
but I guess it's there for a reason for older windows versions. :)



     import Control.Concurrent
     import Network
     import System.IO

     main :: IO ()
     main = withSocketsDo $ do
         forkIO waitAndPong
         ping

     -- The basic server
     waitAndPong :: IO ()
     waitAndPong = do
         socket <- listenOn (PortNumber 1234)
         (handle,_,_) <- accept socket
         hSetBuffering handle LineBuffering
         incoming <- hGetLine handle
         putStrLn ("> " ++ incoming)
         hPutStrLn handle "pong"

     -- The basic client
     ping :: IO ()
     ping = do
         handle <- connectTo "localhost" (PortNumber 1234)
         hSetBuffering handle LineBuffering
         hPutStrLn handle "ping"
         incoming <- hGetLine handle
         putStrLn ("< " ++ incoming)
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Michael Litchard
I tried this as an example and got the following error when running.

net.exe: connect: failed (Connection refused (WSAECONNREFUSED))

Firewall is off, running as administrator

Windows is Windows 7 Enterprise.

Advice on what to do next is appreciated

On Tue, Nov 2, 2010 at 1:24 PM, Nils Schweinsberg <[hidden email]> wrote:
Am 02.11.2010 19:57, schrieb Michael Litchard:

got any urls with examples?

Sure, see this short server-client-ping-pong application.

By the way, I noticed that you don't need withSocketsDo on windows 7, but I guess it's there for a reason for older windows versions. :)



   import Control.Concurrent
   import Network
   import System.IO

   main :: IO ()
   main = withSocketsDo $ do
       forkIO waitAndPong
       ping

   -- The basic server
   waitAndPong :: IO ()
   waitAndPong = do
       socket <- listenOn (PortNumber 1234)
       (handle,_,_) <- accept socket
       hSetBuffering handle LineBuffering
       incoming <- hGetLine handle
       putStrLn ("> " ++ incoming)
       hPutStrLn handle "pong"

   -- The basic client
   ping :: IO ()
   ping = do
       handle <- connectTo "localhost" (PortNumber 1234)
       hSetBuffering handle LineBuffering
       hPutStrLn handle "ping"
       incoming <- hGetLine handle
       putStrLn ("< " ++ incoming)

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Michael Litchard
freenode figured this out. Pasting here for future reference.


import Control.Concurrent
import Network
import System.IO

main :: IO ()
main = withSocketsDo $ do
m <- newEmptyMVar
forkIO (waitAndPong m)
ping m

-- The basic server
waitAndPong :: MVar () -> IO ()
waitAndPong m = do
socket <- listenOn (PortNumber 8000)
putMVar m ()
(handle,_,_) <- accept socket
hSetBuffering handle LineBuffering
incoming <- hGetLine handle
putStrLn ("> " ++ incoming)
hPutStrLn handle "pong"

-- The basic client
ping :: MVar () -> IO ()
ping m = do
_ <- takeMVar m
handle <- connectTo "localhost" (PortNumber 8000)
hSetBuffering handle LineBuffering
hPutStrLn handle "ping"
incoming <- hGetLine handle
putStrLn ("< " ++ incoming)


On Thu, Jan 20, 2011 at 6:17 PM, Michael Litchard <[hidden email]> wrote:
I tried this as an example and got the following error when running.

net.exe: connect: failed (Connection refused (WSAECONNREFUSED))

Firewall is off, running as administrator

Windows is Windows 7 Enterprise.

Advice on what to do next is appreciated


On Tue, Nov 2, 2010 at 1:24 PM, Nils Schweinsberg <[hidden email]> wrote:
Am 02.11.2010 19:57, schrieb Michael Litchard:

got any urls with examples?

Sure, see this short server-client-ping-pong application.

By the way, I noticed that you don't need withSocketsDo on windows 7, but I guess it's there for a reason for older windows versions. :)



   import Control.Concurrent
   import Network
   import System.IO

   main :: IO ()
   main = withSocketsDo $ do
       forkIO waitAndPong
       ping

   -- The basic server
   waitAndPong :: IO ()
   waitAndPong = do
       socket <- listenOn (PortNumber 1234)
       (handle,_,_) <- accept socket
       hSetBuffering handle LineBuffering
       incoming <- hGetLine handle
       putStrLn ("> " ++ incoming)
       hPutStrLn handle "pong"

   -- The basic client
   ping :: IO ()
   ping = do
       handle <- connectTo "localhost" (PortNumber 1234)
       hSetBuffering handle LineBuffering
       hPutStrLn handle "ping"
       incoming <- hGetLine handle
       putStrLn ("< " ++ incoming)

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Tako Schotanus
Just starting out here so I don't know what I'm doing yet, but this one doesn't compile for me.

  ping.hs:19:13: parse error on input `<-'

So am I doing something stupid here or is there something wrong with the code?

-Tako


On Fri, Jan 21, 2011 at 04:48, Michael Litchard <[hidden email]> wrote:
freenode figured this out. Pasting here for future reference.


import Control.Concurrent
import Network
import System.IO

main :: IO ()
main = withSocketsDo $ do
m <- newEmptyMVar
forkIO (waitAndPong m)
ping m

-- The basic server
waitAndPong :: MVar () -> IO ()
waitAndPong m = do
socket <- listenOn (PortNumber 8000)
putMVar m ()

(handle,_,_) <- accept socket
hSetBuffering handle LineBuffering
incoming <- hGetLine handle
putStrLn ("> " ++ incoming)
hPutStrLn handle "pong"

-- The basic client
ping :: MVar () -> IO ()
ping m = do
_ <- takeMVar m
handle <- connectTo "localhost" (PortNumber 8000)

hSetBuffering handle LineBuffering
hPutStrLn handle "ping"
incoming <- hGetLine handle
putStrLn ("< " ++ incoming)


On Thu, Jan 20, 2011 at 6:17 PM, Michael Litchard <[hidden email]> wrote:
I tried this as an example and got the following error when running.

net.exe: connect: failed (Connection refused (WSAECONNREFUSED))

Firewall is off, running as administrator

Windows is Windows 7 Enterprise.

Advice on what to do next is appreciated


On Tue, Nov 2, 2010 at 1:24 PM, Nils Schweinsberg <[hidden email]> wrote:
Am 02.11.2010 19:57, schrieb Michael Litchard:

got any urls with examples?

Sure, see this short server-client-ping-pong application.

By the way, I noticed that you don't need withSocketsDo on windows 7, but I guess it's there for a reason for older windows versions. :)



   import Control.Concurrent
   import Network
   import System.IO

   main :: IO ()
   main = withSocketsDo $ do
       forkIO waitAndPong
       ping

   -- The basic server
   waitAndPong :: IO ()
   waitAndPong = do
       socket <- listenOn (PortNumber 1234)
       (handle,_,_) <- accept socket
       hSetBuffering handle LineBuffering
       incoming <- hGetLine handle
       putStrLn ("> " ++ incoming)
       hPutStrLn handle "pong"

   -- The basic client
   ping :: IO ()
   ping = do
       handle <- connectTo "localhost" (PortNumber 1234)
       hSetBuffering handle LineBuffering
       hPutStrLn handle "ping"
       incoming <- hGetLine handle
       putStrLn ("< " ++ incoming)

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Albert Y. C. Lai
On 11-01-21 03:13 AM, Tako Schotanus wrote:
> Just starting out here so I don't know what I'm doing yet, but this one
> doesn't compile for me.
>
>    ping.hs:19:13: parse error on input `<-'

The original code contains no parse error.

When you tranfer it to your editor, you may accidentally change
indentation, which causes such parse errors.

Some editors add tabs behind your back to confound indentation further.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: windows network programming

Tako Schotanus
You're probably right, I just tried at again at home and here it works.

Thanks,
-Tako


On Fri, Jan 21, 2011 at 23:23, Albert Y. C. Lai <[hidden email]> wrote:
On 11-01-21 03:13 AM, Tako Schotanus wrote:
Just starting out here so I don't know what I'm doing yet, but this one
doesn't compile for me.

  ping.hs:19:13: parse error on input `<-'

The original code contains no parse error.

When you tranfer it to your editor, you may accidentally change indentation, which causes such parse errors.

Some editors add tabs behind your back to confound indentation further.


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe