Git Product home page Git Product logo

tcp_server's Introduction

TCPServer

Package tcp_server created to help build TCP servers faster. Designed to work with text only. Originally forked from https://github.com/firstrow/tcp_server and modified.

Install package

> go get github.com/tech10/tcp_server

Usage:

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

package main

import "github.com/tech10/tcp_server"

func main() {
	server := tcp_server.New("localhost:9999")

	server.OnNewClient(func(c *tcp_server.Client) bool {
		// new client connected
		// lets send a message
		c.Send("Hello\n")
		//Now let's accept the connection.
		return true
	})
	server.OnNewMessage(func(c *tcp_server.Client, message string) {
		// new message received
		// Let's broadcast it to everyone.
		c.SendAll(message, nil)
	})
	server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
		// connection with client lost
	})

	err := server.Start()
	if err != nil {
		return
		}
	server.Wait()
}

Contributing

To contribute:

  1. Install as usual (go get -u github.com/tech10/tcp_server)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Ensure everything works and the tests pass (go test)
  4. Make sure there aren't any data races (go test -race)
  5. 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]:tech10/tcp_server.git)
  3. Complete all the tests stated above.
  4. Push to the branch (git push fork my-new-feature)
  5. Create a new Pull Request on GitHub

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.