2024-11-05 13:58:17 +08:00

46 lines
893 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"log"
"net"
"test-proxy-go/common"
"github.com/gorilla/websocket"
)
const (
localPort = ":1080"
websocketAddress = "ws://proxy.yuchat.top/ws"
)
func main() {
// 启动TCP监听
listener, err := net.Listen("tcp", localPort)
if err != nil {
log.Fatal("启动服务失败,错误信息: ", err)
return
}
log.Println("监听TCP端口成功端口", localPort)
for {
conn, err := listener.Accept()
log.Println("有新的连接:", conn.RemoteAddr())
if err != nil {
log.Println("Error accepting connection:", err)
continue
}
wsConn, _, err := websocket.DefaultDialer.Dial(websocketAddress, nil)
if err != nil {
log.Println("Websocket连接失败:", err)
return
}
log.Println("Websocket连接成功端口", websocketAddress)
go common.WsToTcpHandler(conn, wsConn)
go common.TcpToWsHandler(conn, wsConn)
}
}