Skip to content

Commit eb6d75d

Browse files
Anton GushchaAnton Gushcha
authored andcommitted
Update tutorial-NT2.md
Add withSocketsDo for Windows platform, fromString is now pack
1 parent 9aeb3da commit eb6d75d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tutorials/tutorial-NT2.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,18 @@ because it is simpler. We first need a bunch of imports:
6868

6969
{% highlight haskell %}
7070
import Network.Transport
71-
import Network.Transport.TCP (createTransport)
71+
import Network.Transport.TCP (createTransport, defaultTCPParameters)
72+
import Network.Socket.Internal (withSocketsDo)
7273
import System.Environment
7374
import Data.ByteString.Char8
7475
import Control.Monad
7576
{% endhighlight %}
7677

77-
The client will consist of a single main function.
78+
The client will consist of a single main function. [withSocketsDo](http://hackage.haskell.org/package/network-2.6.2.1/docs/Network-Socket-Internal.html#v:withSocketsDo) is needed for Windows platform.
7879

7980
{% highlight haskell %}
8081
main :: IO ()
81-
main = do
82+
main = withSocketsDo $ do
8283
{% endhighlight %}
8384

8485
When we start the client we expect three command line arguments.
@@ -157,14 +158,14 @@ That's it! Here is the entire client again:
157158

158159
{% highlight haskell %}
159160
main :: IO ()
160-
main = do
161+
main = withSocketsDo $ do
161162
[host, port, serverAddr] <- getArgs
162163
Right transport <- createTransport host port
163164
Right endpoint <- newEndPoint transport
164165

165-
let addr = EndPointAddress (fromString serverAddr)
166+
let addr = EndPointAddress (pack serverAddr)
166167
Right conn <- connect endpoint addr ReliableOrdered defaultConnectHints
167-
send conn [fromString "Hello world"]
168+
send conn [pack "Hello world"]
168169
close conn
169170

170171
replicateM_ 3 $ receive endpoint >>= print
@@ -180,7 +181,8 @@ start with a bunch of imports:
180181

181182
{% highlight haskell %}
182183
import Network.Transport
183-
import Network.Transport.TCP (createTransport)
184+
import Network.Transport.TCP (createTransport, defaultTCPParameters)
185+
import Network.Socket.Internal (withSocketsDo)
184186
import Control.Concurrent
185187
import Data.Map
186188
import Control.Exception
@@ -191,10 +193,10 @@ We will write the main function first:
191193

192194
{% highlight haskell %}
193195
main :: IO ()
194-
main = do
196+
main = withSocketsDo $ do
195197
[host, port] <- getArgs
196198
serverDone <- newEmptyMVar
197-
Right transport <- createTransport host port
199+
Right transport <- createTransport host port defaultTCPParameters
198200
Right endpoint <- newEndPoint transport
199201
forkIO $ echoServer endpoint serverDone
200202
putStrLn $ "Echo server started at " ++ show (address endpoint)

0 commit comments

Comments
 (0)