tcp传输不再丢包

master v0.1.16
兔子 5 years ago
parent 7d30c2ddc9
commit 196a469c34

@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra"
)
var Version string = "0.1.15"
var Version string = "0.1.16"
var Maincmd = &cobra.Command{
Use: "",

@ -224,7 +224,7 @@ func tcpupload(file, prefix string, mytcp net.Conn) error {
time.Sleep(time.Millisecond * 100)
sakura++
if sakura > 50 {
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7})
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7})
time.Sleep(time.Millisecond * 100)
mytcp.Write([]byte("victorique&" + stat.Name() + "&" + prefix))
}
@ -237,9 +237,9 @@ func tcpupload(file, prefix string, mytcp net.Conn) error {
if err != nil {
if err == io.EOF {
err = nil
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7})
for !backsck {
time.Sleep(time.Millisecond * 150)
mytcp.Write([]byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7})
}
backsck = false
break
@ -347,7 +347,7 @@ var tcprecvcmd = &cobra.Command{
defer conns.Close()
var sum int
for {
buf := make([]byte, 524288)
buf := make([]byte, 393216)
n, err := conns.Read(buf)
if !canrecv {
@ -364,10 +364,13 @@ var tcprecvcmd = &cobra.Command{
canrecv = true
name = str[1]
prefix := str[2]
if runtime.GOOS != "windows" {
prefix = strings.Replace(prefix, "\\", "/", -1)
}
if prefix == "" {
fpdst, err = os.Create("./" + name)
} else {
fpdst, err = os.Create(prefix + "/" + name)
fpdst, err = os.Create(prefix + name)
}
if err != nil {
fmt.Println(err)
@ -381,18 +384,19 @@ var tcprecvcmd = &cobra.Command{
return
}
} else {
if n < 524288 && buf[n-1] == byte(7) {
if buf[n-1] == byte(7) && buf[n-2] == byte(2) && buf[n-3] == byte(1) {
ok := func() bool {
for k, v := range []byte{1, 9, 9, 6, 1, 1, 2, 7, 6, 6, 6, 1, 1, 2, 7} {
if buf[n-15+k] != v {
for k, v := range []byte{1, 9, 9, 6, 1, 1, 2, 7} {
if buf[n-8+k] != v {
return false
}
}
return true
}()
if ok {
if n > 15 {
fpdst.Write(buf[0 : n-15])
if n > 8 {
fpdst.Write(buf[0 : n-8])
sum += n - 8
}
fmt.Printf("已写入:%d 字节\n", sum)
fmt.Println(name + "接收成功\n")

Loading…
Cancel
Save