SHARE
TWEET

Untitled

a guest May 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "io"
  5.     "log"
  6.     "net"
  7.     "time"
  8. )
  9.  
  10. var targetAddr *net.TCPAddr
  11.  
  12. func main() {
  13.  
  14.     addr, _ := net.ResolveTCPAddr("tcp", ":8089")
  15.     tcpAddr, _ := net.ResolveTCPAddr("tcp", ":6379")
  16.     targetAddr = tcpAddr
  17.     listener, _ := net.ListenTCP("tcp", addr)
  18.     for  {
  19.         conn, _ := listener.AcceptTCP()
  20.         go server(conn)
  21.     }
  22. }
  23.  
  24. func server(conn *net.TCPConn)  {
  25.     conn.SetKeepAlive(true)
  26.     conn.SetKeepAlivePeriod(time.Second * 15)
  27.     tcpConn, _ := net.DialTCP("tcp", nil, targetAddr)
  28.     defer tcpConn.Close()
  29.     tcpConn.SetKeepAlive(true)
  30.     tcpConn.SetKeepAlivePeriod(time.Second * 15)
  31.     bools := make(chan bool)
  32.     go func() {
  33.         _, err := io.Copy(tcpConn, conn)
  34.         log.Println(err)
  35.         bools <- true
  36.     }()
  37.  
  38.     go func() {
  39.         _, err := io.Copy(conn, tcpConn)
  40.         log.Println(err)
  41.         bools <- true
  42.     }()
  43.  
  44.     <- bools
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top