Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "io"
  6. "net"
  7. )
  8.  
  9. func main() {
  10. ln, err := net.Listen("tcp", ":8080")
  11. if err != nil {
  12. panic(err)
  13. }
  14.  
  15. for {
  16. conn, err := ln.Accept()
  17. if err != nil {
  18. panic(err)
  19. }
  20.  
  21. go handleRequest(conn)
  22. }
  23. }
  24.  
  25. func handleRequest(conn net.Conn) {
  26. fmt.Println("new client")
  27.  
  28. proxy, err := net.Dial("tcp", "127.0.0.1:80")
  29. if err != nil {
  30. panic(err)
  31. }
  32.  
  33. fmt.Println("proxy connected")
  34. go copyIO(conn, proxy)
  35. go copyIO(proxy, conn)
  36. }
  37.  
  38. func copyIO(src, dest net.Conn) {
  39. defer src.Close()
  40. defer dest.Close()
  41. io.Copy(src, dest)
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement