Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
network port forwarding in go lang
package main
import (
func main() {
ln, err := net.Listen("tcp", ":8080")
if err != nil {
for {
conn, err := ln.Accept()
if err != nil {
go handleRequest(conn)
func handleRequest(conn net.Conn) {
fmt.Println("new client")
proxy, err := net.Dial("tcp", "")
if err != nil {
fmt.Println("proxy connected")
go copyIO(conn, proxy)
go copyIO(proxy, conn)
func copyIO(src, dest net.Conn) {
defer src.Close()
defer dest.Close()
io.Copy(src, dest)

This comment has been minimized.

Copy link
Owner Author

@qhwa qhwa commented Jan 5, 2016

This go app forwards datas from localhost:8080 to localhost:80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment