Node sockets with a Signal interface

License: LGPL-3.0

Language: PureScript


Node sockets with a Signal interface.


Read the API documentation.


Connect to a socket and subscribe to a signal of socket events:

import Signal.Socket as Socket

main = do
  socket <- Socket.connect "localhost" 31337
  eventSignal <- Socket.subscribe socket

The signal is of type Signal (Socket.Event String), and the Socket.Event datatype looks like this:

import Control.Monad.Eff.Exception (Error)

data Event a = Connecting
             | Connected
             | Drain
             | Closed
             | Timeout
             | Data a
             | Error Error

To process the event stream:

  Signal.runSignal $ eventSignal ~> onSocketEvent
  where onSocketEvent Connected = Socket.write socket "hai lol!"
        onSocketEvent Timeout = Socket.end socket
        onSocketEvent (Data s) = Socket.write socket $ "hi " ++ s
        -- etc

You can also get a signal of just the data from the socket (of type Signal (Maybe String), which will start at Nothing, yield Justs of each data packet, then go back to Nothing when the socket closes):

  let dataSignal = S.onlyData eventSignal

If you prefer to receive lines, you can split the data stream on a given string, eg. newlines - this will also buffer output for you until a complete line has been received:

  let lines = S.split "\r\n" dataSignal


Copyright 2016 Bodil Stokke

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see

Project Statistics

Sourcerank 3
Repository Size 23.4 KB
Stars 5
Forks 2
Watchers 1
Open issues 1
Dependencies 9
Contributors 2
Tags 4
Last updated
Last pushed

Top Contributors See all

Bodil Stokke Bodil Stokke

Packages Referencing this Repo

Node sockets with a Signal interface
Latest release v3.0.0 - Published - 5 stars

Recent Tags See all

v3.0.0 October 21, 2016
v2.0.0 July 28, 2016
v1.1.0 April 18, 2016
v1.0.0 April 18, 2016

Something wrong with this page? Make a suggestion

Last synced: 2018-09-18 11:19:33 UTC

Login to resync this repository