Coder Social home page Coder Social logo

go-munproto's Introduction

Support multiple protocols such as http, https, socks5, etc..., on one port.

Install

go get github.com/sintanial/go-munproto

Docs

https://godoc.org/github.com/sintanial/go-munproto

Usage

package main

import (
	"net"
	"github.com/sintanial/go-munproto"
	"fmt"
	"log"
	"os"
)

func main() {
	l, err := net.Listen("tcp", ":8080")
	if err != nil {
		panic(err)
	}

	munproto.RegisterProtoDefault()

	dispatcher := munproto.NewDispatcher(l)
	dispatcher.Logger = log.New(os.Stdout, "[munproto debug] ", log.LstdFlags)

	// return interface net.Listener
	// sequence of calls very important, for more detailes see Dispatcher.Listener doc 
	socks5Listener := dispatcher.Listener("socks5")
	httpsListener := dispatcher.Listener("https")
	httpListener := dispatcher.Listener("http")

    // if you use github.com/armon/go-socks5 for create SOCKS5 library,
    // you can create socks5.Server{} and pass socks5Listener to socks5.Server.Serve()
	go serve("socks5", socks5Listener)
	
	// you can create http.Server{} and pass httpListener to http.Server.Serve()
	go serve("http", httpListener)
	go serve("https", httpsListener)

	if err := dispatcher.Listen(); err != nil {
		panic(err)
	}
}

func serve(proto string, l net.Listener) {
	for {
		conn, err := l.Accept()
		if err != nil {
			panic(err)
		}

		fmt.Println(fmt.Sprintf("handle %s conn", proto), conn.RemoteAddr())
		conn.Close()
	}
}

TODO

Write tests

go-munproto's People

Contributors

sintanial avatar

Watchers

 avatar  avatar

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.