Created
June 29, 2017 19:14
-
-
Save HayatoDoi/03d7798ec91023025445e50f4ab4f968 to your computer and use it in GitHub Desktop.
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 ( | |
"fmt" | |
"net" | |
) | |
func main() { | |
tcpAddr, _ := net.ResolveTCPAddr("tcp", ":9000") | |
listner, _ := net.ListenTCP("tcp", tcpAddr) | |
for { | |
conn, _ := listner.Accept() | |
go func(conn net.Conn) { | |
defer conn.Close() | |
revpro(conn) | |
}(conn) | |
} | |
} | |
func revpro(conn net.Conn) { | |
buf := make([]byte, 10240) | |
conn.Read(buf) | |
req := string(buf) | |
fmt.Print(req) | |
//クライアントの作成 | |
client, _ := net.Dial("tcp", ":80") | |
defer client.Close() | |
client.Write([]byte(req)) | |
client.Read(buf) | |
res := string(buf) | |
//受け取ったデータをそのままリバース | |
conn.Write([]byte(res)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment