gopkg.in/dedis/onet.v2@v2.0.0-20181115163211-c8f3724038a7/simul/monitor/proxy.go (about)

     1  package monitor
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  )
     7  
     8  // NewProxy returns a new TCP proxy listening on addr:listenPort, which forwards
     9  // connections to localhost:toPort.
    10  func NewProxy(toPort uint16, addr string, listenPort uint16) (*TCPProxy, error) {
    11  	ln, err := net.Listen("tcp", fmt.Sprintf("%v:%v", addr, listenPort))
    12  	if err != nil {
    13  		return nil, err
    14  	}
    15  
    16  	e := make([]*net.SRV, 1)
    17  	e[0] = new(net.SRV)
    18  	e[0].Target = "localhost"
    19  	e[0].Port = toPort
    20  
    21  	return &TCPProxy{
    22  		Listener:  ln,
    23  		Endpoints: e,
    24  	}, nil
    25  }