Skip to content

Instantly share code, notes, and snippets.

@HayatoDoi
Created June 29, 2017 19:14
Show Gist options
  • Save HayatoDoi/03d7798ec91023025445e50f4ab4f968 to your computer and use it in GitHub Desktop.
Save HayatoDoi/03d7798ec91023025445e50f4ab4f968 to your computer and use it in GitHub Desktop.
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