forked from makazeu/AnotherSteamCommunityFix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpproxy.go
More file actions
37 lines (31 loc) · 666 Bytes
/
tcpproxy.go
File metadata and controls
37 lines (31 loc) · 666 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package AnotherSteamCommunityFix
import (
"io"
"log"
"net"
"time"
)
func handleConn(conn net.Conn, remote string) {
defer conn.Close()
remoteConn, err := net.DialTimeout("tcp", remote, 15*time.Second)
if err != nil {
log.Println("dial remote error:", err)
return
}
defer remoteConn.Close()
go io.Copy(conn, remoteConn)
io.Copy(remoteConn, conn)
}
func StartServingTCPProxy(local, remote string) {
listener, err := net.Listen("tcp4", local)
if err != nil {
fatalLogger.Fatal("listen tcp error:", err)
}
for {
conn, err := listener.Accept()
if err != nil {
log.Println("accept tcp error:", err)
}
go handleConn(conn, remote)
}
}