Last active
June 15, 2018 11:52
-
-
Save lzjluzijie/ee3a10249c02253bffcab1dc31e15d08 to your computer and use it in GitHub Desktop.
tcp reverse proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"fmt" | |
"io" | |
) | |
func main(){ | |
listener, err := net.Listen("tcp", ":2333") | |
if err != nil { | |
fmt.Println(err.Error()) | |
return | |
} | |
fmt.Println("ok") | |
for { | |
conn, err := listener.Accept() | |
if err != nil { | |
fmt.Println(err.Error()) | |
return | |
} | |
defer conn.Close() | |
fmt.Println("accepted") | |
go func() { | |
c, err := net.Dial("tcp", "cryptonightheavy.usa.nicehash.com:3364") | |
if err != nil { | |
fmt.Println(err.Error()) | |
return | |
} | |
defer c.Close() | |
go io.Copy(conn, c) | |
io.Copy(c, conn) | |
}() | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment