golang tcp server

Related tags

Network tcp_server
Overview

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 [email protected]: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.

Comments
  • Maledog patch

    Maledog patch

    Why read the line, if you can read the bytes? I added more control of the size of read buffer. If you use input buffering, then let's use output buffering. And I want to know that the server has started.

    opened by maledog 3
  • May be add

    May be add

    func (c * Client) GetLocalAddress() net.Addr{ return c.conn.LocalAddr() }

    func (c * Client) GetRemoteAddress() net.Addr{ return c.conn.RemoteAddr() }

    for get local remote address?

    opened by truebest 2
  • Clean up code and print error messages to users

    Clean up code and print error messages to users

    As it currently is, the actual error messages received aren't printed to users. This fixes that.

    The New() function can be used in NewWithTLS() as well, I use that function rather than repeating code. This will make future modification easier.

    The unneeded go.sum file, which was empty, has been deleted.

    opened by tech10 1
  • Add module support, check more errors.

    Add module support, check more errors.

    Go 1.17 will ignore the GO111MODULE environment variable, so I have added module support and created more error checking.

    I attempted to bump the Travis CI to use go 1.11, but the tests are still failing with the automated tests due to the conveyance package. They are working perfectly on my computer running go 1.16, though. I'm still investigating this.

    opened by tech10 1
  • TLS support

    TLS support

    Support creating TLS server. Tested passed with my C# TLS client. Sorry I don't have time to write the unit test for this. Anyone who want to secure TCP connection can use this patch.

    opened by ncd 1
  • NewClientCallback called on the new goroutine

    NewClientCallback called on the new goroutine

    NewClientCallback should be called on the new routine. in this way, it will never block new client connection. To test that try to add timer.Sleep in NewClientCallback callback function, this will prevent the server accepting new connection.

    opened by abshammeri 1
  • Difficulties integrating into an existing application

    Difficulties integrating into an existing application

    There will be some difficulties with integration of this library into another application.

    At the moment, it is written in such a way that the library is strictly used for creating a TCP server only. However, I could see instances where one might desire to integrate this library into another application. There are some problems with its current implementation.

    • The library implements its own logging, and will shut down the entire program if an error is received that prevents the server from starting. Some programs might want to log data and shut down themselves in a clean, controlled manner. This library prevents this from occurring properly.
    • There is no way to stop a server once it's started. If a program integrating this library is intercepting process signals, or is otherwise being shut down through another means, the server won't close cleanly in a controlled manner that will stop accepting connections, clients, disconnect all clients, and terminate all running goroutines the server has spawned. The server will remain active and the goroutine to accept connections, at the very least, will still be operational.

    Changes to the server might create some breaking changes to clients relying on it for use, such as if they expect the server to stop the program if it can't initialize, something that isn't wise programming. All go programs should handle errors in a controlled manner.

    I would propose these issues at the minimum be addressed, so as to allow for integration of this library into existing applications, as well as to allow for the program to log its own errors properly.

    opened by tech10 0
Releases(v1.0)
Owner
null
Tcp chat go - Create tcp chat in golang

TCP chat in GO libs Go net package and goroutines and channels tcp tcp or transm

amirbahador 0 Feb 5, 2022
TcpRoute , TCP 层的路由器。对于 TCP 连接自动从多个线路(电信、联通、移动)、多个域名解析结果中选择最优线路。

TcpRoute2 TcpRoute , TCP 层的路由器。对于 TCP 连接自动从多个线路(允许任意嵌套)、多个域名解析结果中选择最优线路。 TcpRoute 使用激进的选路策略,对 DNS 解析获得的多个IP同时尝试连接,同时使用多个线路进行连接,最终使用最快建立的连接。支持 TcpRoute

GameXG 860 Dec 27, 2022
TCP output for beats to send events over TCP socket.

beats-tcp-output How To Use Clone this project to elastic/beats/libbeat/output/ Modify elastic/beats/libbeat/publisher/includes/includes.go : // add i

ichx 2 Aug 25, 2022
“Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server!

Dear Port80 About The Project: “Dear Port80” is a zero-config TCP proxy server that hides SSH connection behind a HTTP server! +---------------------

Abbas Gheydi 6 Jun 29, 2022
golang tcp server

TCPServer Package tcp_server created to help build TCP servers faster. Install package go get -u github.com/firstrow/tcp_server Usage: NOTICE: OnNewMe

null 420 Dec 28, 2022
EasyTCP is a light-weight and less painful TCP server framework written in Go (Golang) based on the standard net package.

EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful.

zxl 551 Jan 7, 2023
A socks5 server(tcp/udp) written in golang.

socks5-server A socks5 server(tcp/udp) written in golang. Usage Usage of /main: -l string local address (default "127.0.0.1:1080") -p stri

null 32 Nov 20, 2022
Client-Server tcp-based file transfer application in GoLang

Клиент-серверный файловый сервис на базе протокола TCP Клиент client.go шифрует свои файлы алгоритмом AES с режимом CBC и помещает их на сервер server

null 1 Apr 1, 2022
Golang pow implementation client <-> server over UDP and TCP protocols

Client <-> server over UDP and TCP pow protocol Denial-of-Service-attacks are a typical situation when providing services over a network. A method for

Nikita Kryuchkov 0 Jan 13, 2022
A TCP Server Framework with graceful shutdown, custom protocol.

xtcp A TCP Server Framework with graceful shutdown,custom protocol. Usage Define your protocol format: Before create server and client, you need defin

xfx 139 Dec 7, 2022
TCP echo server

Echo v0.1.2 What TCP Echo server. RFC862 implementation. Usage of package package main import ( "context" "github.com/boratanrikulu/echo" ) func

Bora Tanrıkulu 5 Jul 26, 2021
A TCP socket based chat server implemented using Go

Go Chat Server A better TCP socket chat server implemented using Go Connecting nc localhost 5000 Docker Build the container image docker build -t grub

Christopher Gruber 0 Oct 16, 2021
Uses the Finger user information protocol to open a TCP connection that makes a request to a Finger server

Finger Client This client uses the Finger user information protocol to open a TCP connection that makes a request to a Finger server. Build and Run Ru

Linda Xiao 0 Oct 7, 2021
TCP based Client/Server chat CLI in Go

TCP based Client/Server chat CLI in Go Written in Go, this is a simple implementation of a TCP server that can detect new clients connecting and disco

Dhruv Krishnamachari 2 Jul 27, 2022
Make TCP connection storm between server and client for benchmarking network stuff

Make TCP connection storm between server and client for benchmarking network stuff

Masahiro Nagano 2 Nov 14, 2021
Client - Server TCP Chat For String Messages And Random Files

GoChat Client - Server TCP Chat For String Messages And Random Files GoChat is a chat for string messages and random files using Golorem by Derek A. R

Brian GL 0 Sep 29, 2021
Tcp-proxy - A dead simple reverse proxy server.

tcp-proxy A proxy that forwords from a host to another. Building go build -ldflags="-X 'main.Version=$(git describe --tags $(git rev-list --tags --max

Injamul Mohammad Mollah 0 Jan 2, 2022
Simple TCP proxy to visualise NATS client/server traffic

NATS uses a simple publish/subscribe style plain-text protocol to communicate between a NATS Server and its clients. Whilst this connection should remain opaque to the user, it can be quite handy to see the data being passed from time to time - this tool does just that (it also saves me loading Wireshark and filtering the NATS traffic).

Joseph Woodward 0 Jan 15, 2022
Mutual TLS encryption TCP proxy with golang

mtls-tcp-proxy Mutual Authentication TLS encryption TCP proxy with golang Why? I created this because of sometimes, it is not possible for us to estab

Habibie Faried 3 Oct 17, 2022