Tweet-sized TCP proxy in go


(Nick Keets) #1

I found this tweet nice for inspiration and also to know what the "competition" looks like.

package main

import (
    "io"
    "net"
)

func main() {
    s, _ := net.Listen("tcp", ":8080")
    for {
        l, _ := s.Accept()
        r, _ := net.Dial("tcp", "localhost:8081")
        go io.Copy(l, r)
        go io.Copy(r, l)
    }
}

https://twitter.com/heptajohn/status/957748274529734658


(Helge Heß) #2

The Noze.io version is arguably nicer ;-)

import net

createServer { sock in
  connect(8081, "localhost") { client in
    sock   | client
    client | sock
  }
}
.listen(8080)