golang tcp server
Clone or download
firstrow Merge pull request #12 from abshammeri/abshammeri-patch-NewClientCall…
…back-on-new-goroutine

NewClientCallback called on the new goroutine
Latest commit 662e425 Sep 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Added travis config file Mar 24, 2017
LICENSE Added license file Oct 17, 2016
readme.md Update readme.md Jun 7, 2017
tcp_server.go Update tcp_server.go Sep 4, 2018
tcp_server_test.go Update tcp_server_test.go Apr 20, 2015

readme.md

Build Status

TCPServer

Package tcp_server created to help build TCP servers faster.

Install package

go get -u github.com/firstrow/tcp_server

Usage:

NOTICE: OnNewMessage callback will receive new message only if it's ending with \n

package main

import "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 git@github.com:firstrow/tcp_server.git)
  3. Push to the branch (git push fork my-new-feature)
  4. Create a new Pull Request on GitHub

Notice: Always use the original import path by installing with go get.