Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fourcube/ltcp
Simple TCP Handlers in golang
https://github.com/fourcube/ltcp
Last synced: 4 days ago
JSON representation
Simple TCP Handlers in golang
- Host: GitHub
- URL: https://github.com/fourcube/ltcp
- Owner: fourcube
- License: mit
- Created: 2015-04-30T12:46:43.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-01T12:57:24.000Z (over 9 years ago)
- Last Synced: 2024-12-22T19:07:38.937Z (29 days ago)
- Language: Go
- Size: 137 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ltcp
[![GoDoc](https://godoc.org/github.com/fourcube/ltcp?status.svg)](http://godoc.org/github.com/fourcube/ltcp) [![Build Status](https://travis-ci.org/fourcube/ltcp.svg?branch=master)](https://travis-ci.org/fourcube/ltcp)
ltcp is a simple library providing an easy way to spawn tcp handlers. It might be useful for your tests.
Handlers are functions of type `func (net.Conn)`.
Sample code:
```go
package mainimport (
"github.com/fourcube/ltcp"
"net"
)func main() {
// Listens on some random, available port on all interfaces
// handles all connections with the ltcp.EchoHandler
//
// You can send ltcp.Shutdown through the 'done' channel to stop the listener.
//
done := make(chan struct{})
addr, err := ltcp.ListenAny(ltcp.EchoHandler, done)conn, err := net.Dial("tcp", addr.String())
if err != nil {
// ...
}// ... do whatever with the connection
conn.Close()
// The listener will shutdown when it receives something on the done channel
// It then closes the done channel
done <- ltcp.Shutdown
<-done
}
```