The connection package

[Tags: bsd3, library]

Simple network library for all your connection need.

Features: Really simple to use, SSL/TLS, SOCKS.

This library provides a very simple api to create sockets to a destination with the choice of SSL/TLS, and SOCKS.


[Skip to ReadMe]

Properties

Versions0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.3.1, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5
Change logCHANGELOG.md
Dependenciesbase (>=3 && <5), byteable, bytestring, containers, data-default-class, network (>=2.3), socks (>=0.4), tls (>=1.3), x509 (>=1.5), x509-store (>=1.5), x509-system (>=1.5), x509-validation (>=1.5) [details]
LicenseBSD3
CopyrightVincent Hanquez <vincent@snarc.org>
AuthorVincent Hanquez <vincent@snarc.org>
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
CategoryNetwork
Home pagehttp://github.com/vincenthz/hs-connection
Source repositoryhead: git clone git://github.com/vincenthz/hs-connection
UploadedFri Jun 19 20:32:34 UTC 2015 by VincentHanquez
DistributionsDebian:0.2.4, FreeBSD:0.2.3, LTSHaskell:0.2.4, NixOS:0.2.5, Stackage:0.2.5
Downloads75191 total (894 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Last success reported on 2015-06-19 [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for connection-0.2.5

haskell Connection library

Simple network library for all your connection need.

Features:

Usage

Connect to www.example.com on port 4567 (without socks or tls), then send a byte, receive a single byte, print it, and close the connection:

import qualified Data.ByteString as B
import Network.Connection
import Data.Default

main = do
    ctx <- initConnectionContext
    con <- connectTo ctx $ ConnectionParams
                              { connectionHostname  = "www.example.com"
                              , connectionPort      = 4567
                              , connectionUseSecure = Nothing
                              , connectionUseSocks  = Nothing
                              }
    connectionPut con (B.singleton 0xa)
    r <- connectionGet con 1
    putStrLn $ show r
    connectionClose con

Using a socks proxy is easy, we just need replacing the connectionSocks parameter, for example connecting to the same host, but using a socks proxy at localhost:1080:

con <- connectTo ctx $ ConnectionParams
                       { connectionHostname  = "www.example.com"
                       , connectionPort      = 4567
                       , connectionUseSecure = Nothing
                       , connectionUseSocks  = Just $ SockSettingsSimple "localhost" 1080
                       }

Connecting to a SSL style socket is equally easy, and need to set the UseSecure fields in ConnectionParams:

con <- connectTo ctx $ ConnectionParams
                       { connectionHostname  = "www.example.com"
                       , connectionPort      = 4567
                       , connectionUseSecure = Just def
                       , connectionUseSocks  = Nothing
                       }

And finally, you can start TLS in the middle of an insecure connection. This is great for protocol using STARTTLS (e.g. IMAP, SMTP):

{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString as B
import Data.ByteString.Char8 ()
import Network.Connection
import Data.Default

main = do
    ctx <- initConnectionContext
    con <- connectTo ctx $ ConnectionParams
                              { connectionHostname  = "www.example.com"
                              , connectionPort      = 4567
                              , connectionUseSecure = Nothing
                              , connectionUseSocks  = Nothing
                              }
    -- talk to the other side with no TLS: says hello and starttls
    connectionPut con "HELLO\n"
    connectionPut con "STARTTLS\n"

    -- switch to TLS
    connectionSetSecure ctx con def

    -- the connection is from now on using TLS, we can send secret for example
    connectionPut con "PASSWORD 123\n"
    connectionClose con