You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote some code for the test and it turned out that if the delay is less than 14ms in line 51, then the receiver receives a different number of bytes each time! i.e. it loses packets somewhere?
It turns out that with a delay of 14ms and a packet size of 1024 bytes, the total speed of this KCP is about 71kb/sec ?
Isn't that too little? Tell me if I wrote everything correctly in the code.
sender code:
import (
"crypto/sha1"
"io"
"log"
"os"
"time"
"github.com/xtaci/kcp-go/v5"
"golang.org/x/crypto/pbkdf2"
)
var EOFPACKET = []byte{1023: 0} // 1024 bytes of 0
func main() {
file, _ := os.Open("data.css") // size 236 530 bytes
defer file.Close()
sender("192.168.154.200:12345", "superpass", "salt", 1024, 32, file)
println("ctrl c for exit")
<-make(chan struct{}) // wait
}
// * 127.0.0.1 12345 superpass salt 1024 32
func sender(hostport string, kcp_pass, kcp_salt string, kcp_iterations, kcp_keylen int, DATA io.Reader) error {
key := pbkdf2.Key([]byte(kcp_pass), []byte(kcp_salt), kcp_iterations, kcp_keylen, sha1.New)
block, _ := kcp.NewAESBlockCrypt(key)
sess, err := kcp.DialWithOptions(hostport, block, 10, 3)
if err != nil {
log.Fatal("error dialing:", err)
}
defer sess.Close()
dataBuf := make([]byte, 1024)
totalLen := 0
// written, err := io.Copy(sess, DATA) // lost packets every time
// println("written bytes:", written, " error:", err)
// return nil
for {
println()
time.Sleep(14 * time.Millisecond)
// read from file
n, e := DATA.Read(dataBuf)
if e == io.EOF {
println("EOF")
break
}
if e != nil {
println("error read:", e)
break
}
// println("read n:", n)
totalLen += n
println("read bytes:", n, " total read data:", totalLen)
// println(string(dataBuf[:n]))
sn, es := sess.Write(dataBuf[:n])
if es != nil {
log.Println("error sending:", es)
break
}
println("sent bytes:", sn)
}
println("end of sender")
// send exit to session
sess.Write(EOFPACKET)
return nil
}
I wrote some code for the test and it turned out that if the delay is less than 14ms in line 51, then the receiver receives a different number of bytes each time! i.e. it loses packets somewhere?
It turns out that with a delay of 14ms and a packet size of 1024 bytes, the total speed of this KCP is about 71kb/sec ?
Isn't that too little? Tell me if I wrote everything correctly in the code.
sender code:
receiver code:
output is:
The text was updated successfully, but these errors were encountered: