Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/firstrow/tcp_server
golang tcp server
https://github.com/firstrow/tcp_server
Last synced: about 2 months ago
JSON representation
golang tcp server
- Host: GitHub
- URL: https://github.com/firstrow/tcp_server
- Owner: firstrow
- License: mit
- Archived: true
- Created: 2014-10-13T20:38:42.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2021-11-10T09:30:31.000Z (about 3 years ago)
- Last Synced: 2024-07-31T20:52:37.080Z (4 months ago)
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 426
- Watchers: 22
- Forks: 143
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - tcp_server - Go library for building tcp servers faster. (Networking / Transliteration)
- zero-alloc-awesome-go - tcp_server - Go library for building tcp servers faster. (Networking / Transliteration)
- awesome-go - tcp_server - golang tcp server - ★ 228 (Networking)
- awesome-go-extra - tcp_server - 10-13T20:38:42Z|2021-11-10T09:30:31Z| (Networking / Uncategorized)
- awesome-go-zh - tcp_server
README
[![Build Status](https://travis-ci.org/firstrow/tcp_server.svg?branch=master)](https://travis-ci.org/firstrow/tcp_server)
# TCPServer
Package tcp_server created to help build TCP servers faster.### Install package
``` bash
go get -u github.com/firstrow/tcp_server@latest
```### Usage:
NOTICE: `OnNewMessage` callback will receive new message only if it's ending with `\n`
``` go
package mainimport "github.com/firstrow/tcp_server"
func main() {
server := tcp_server.New("localhost:9999")server.OnNewClient(func(c *tcp_server.Client) {
// new client connected
// lets send some message
c.Send("Hello")
})
server.OnNewMessage(func(c *tcp_server.Client, message string) {
// new message received
})
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
// connection with client lost
})server.Listen()
}
```# Contributing
To hack on this project:
1. Install as usual (`go get -u github.com/firstrow/tcp_server`)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Ensure everything works and the tests pass (`go test`)
4. Commit your changes (`git commit -am 'Add some feature'`)Contribute upstream:
1. Fork it on GitHub
2. Add your remote (`git remote add fork [email protected]:firstrow/tcp_server.git`)
3. Push to the branch (`git push fork my-new-feature`)
4. Create a new Pull Request on GitHubNotice: Always use the original import path by installing with `go get`.