metro: A simple tcp and udp socket server framework

[ bsd3, framework, library, network ] [ Propose Tags ]

Please see the README on GitHub at

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,,
Change log
Dependencies base (>=4.7 && <5), binary, bytestring, hashable, hashmap-io, hslogger, mtl, transformers, unix-time, unliftio [details]
License BSD-3-Clause
Copyright MIT
Author Lupino
Category Network, Framework
Home page
Bug tracker
Source repo head: git clone
Uploaded by Lupino at 2021-04-09T02:49:47Z
Distributions NixOS:
Reverse Dependencies 8 direct, 0 indirect [details]
Downloads 923 total (24 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for metro-

[back to package description]


a simple tcp and udp socket server framework

Quick start with example

import Metro.Class
import Metro.Node
import Metro.TCP
import Metro.Servable
import Metro.Session (SessionT, makeResponse_)

data CustomPacket = CustomPacket { ... }
type CustomPacketId = ...

instance RecvPacket CustomPacket where
  recvPacket recv = ...
instance SendPacket CustomPacket where
  sendPacket pkt send = ...

instance GetPacketId CustomPacketId where
  getPacketId = ...
instance SetPacketId CustomPacketId where
  setPacketId k pkt = ...

type NodeId = ...
data CustomEnv = CustomEnv { ... }
type DeviceT = NodeT CustomEnv NodeId CustomPacketId CustomPacket
type DeviceEnv = NodeEnv1 CustomEnv NodeId CustomPacketId CustomPacket

sessionHandler = makeResponse_ $ \pkt -> ...

sessionGen :: IO CustomPacketId
sessionGen = ..

prepare :: Socket -> ConnEnv tp -> IO (Maybe (NodeId, CustomEnv))
prepare sock connEnv = Just ...

keepalive = 300

bind_port = "tcp://:8080"

startExampleServer = do
  sEnv <- initServerEnv "Example" (tcpConfig "tcp://:8080") sessionGen rawSocket prepare
  void $ forkIO $ startServer sEnv sessionHandler

more see metro-example/src/Metro/Example.hs

Projects use metro