Skip to content

Instantly share code, notes, and snippets.

@jbardin
jbardin / proxy_copy.go
Last active June 28, 2023 22:12
Go TCP Proxy pattern
package proxy
import (
"io"
"log"
"net"
)
func Proxy(srvConn, cliConn *net.TCPConn) {
// channels to wait on the close event for each connection
func (b *backend) handle(c1 *tls.Conn, c *net.TCPConn) {
c2, err := net.DialTCP("tcp", nil, b.addr)
if err != nil {
c1.Close()
return
}
go func() {
err := io.Copy(c2, c1)
if err != nil {
log.Print(err)
[ 'atm',
'binoculars',
'breaking_news',
'camera_gallery',
'cellphone_alert_popup',
'cellphone_ifruit',
'cellphone_prologue',
'countdown',
'darts_scoreboard',
'digiscanner',