Skip to content

Commit

Permalink
远程端连不上的时候把连接关了
Browse files Browse the repository at this point in the history
  • Loading branch information
zanjie1999 committed Oct 12, 2023
1 parent fc4227e commit c019f1d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tcp2ws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tcp over WebSocket (tcp2ws)
// 基于ws的内网穿透工具
// Sparkle 20210430
// 11.0
// 11.1

package main

Expand Down Expand Up @@ -382,6 +382,8 @@ func runServer(wsConn *websocket.Conn) {
udpConn, err = net.DialUDP("udp", nil, udpAddr)
if err != nil {
log.Print("connect to udp err: ", err)
wsConn.WriteMessage(websocket.TextMessage, []byte("tcp2wsSparkleClose"))
wsConn.Close()
return
}

Expand All @@ -395,6 +397,8 @@ func runServer(wsConn *websocket.Conn) {
tcpConn, err = net.Dial("tcp", tcpAddr)
if err != nil {
log.Print("connect to tcp err: ", err)
wsConn.WriteMessage(websocket.TextMessage, []byte("tcp2wsSparkleClose"))
wsConn.Close()
return
}

Expand Down Expand Up @@ -646,7 +650,7 @@ func dnsPreferIpWithTtl(hostname string, ttl uint32) {
func main() {
arg_num := len(os.Args)
if arg_num < 3 {
fmt.Println("TCP over WebSocket (tcp2ws) with UDP support 11.0\nhttps://github.com/zanjie1999/tcp-over-websocket")
fmt.Println("TCP over WebSocket (tcp2ws) with UDP support 11.1\nhttps://github.com/zanjie1999/tcp-over-websocket")
fmt.Println("Client: ws://tcp2wsUrl localPort\nServer: ip:port tcp2wsPort\nUse wss: ip:port tcp2wsPort server.crt server.key")
fmt.Println("Make ssl cert:\nopenssl genrsa -out server.key 2048\nopenssl ecparam -genkey -name secp384r1 -out server.key\nopenssl req -new -x509 -sha256 -key server.key -out server.crt -days 36500")
os.Exit(0)
Expand Down

0 comments on commit c019f1d

Please sign in to comment.