Skip to content
Snippets Groups Projects
Commit 33419135 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Add alternative connection code.

parent 9c5ed1bd
No related branches found
No related tags found
No related merge requests found
> {-# LANGUAGE OverloadedStrings #-}
> module Networkhard where
> import Network.Socket hiding (send, recv)
> import Network.Socket.ByteString.Lazy
> import qualified Data.ByteString.Lazy as B
> getSocket :: HostName -> ServiceName -> IO (Socket, SockAddr)
> getSocket addr port = do
> ad:_ <- getAddrInfo (Just hints) (Just addr) (Just port)
> sock <- socket (addrFamily ad) (addrSocketType ad) (addrProtocol ad)
> return (sock, addrAddress ad)
> where hints = defaultHints { addrSocketType = Stream }
The function test should return the string "LysKOM".
> test :: IO B.ByteString
> test = do
> (sock, addr) <- getSocket "kom.lysator.liu.se" "4894"
> connect sock addr
> send sock "A13HHugo%claptrap"
> recv sock 6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment