kcp-csharp icon indicating copy to clipboard operation
kcp-csharp copied to clipboard

Not working with kcp golang server

Open garlen-javier opened this issue 3 years ago • 6 comments

I tried the example on this project but it seems the kcp for golang doesn’t work. Tried sending a message from this c# script but golang server won’t recognize it.

garlen-javier avatar May 01 '21 15:05 garlen-javier

kcp-csharp currently not supported FEC & Packet level encryption. please disable your golang server FEC & Packet level encryption option

limpo1989 avatar May 01 '21 15:05 limpo1989

Tried it with the minimal example, I just use listen without the encryption example but no luck.

package main

import (
	"fmt"
	"io"
	"log"
	"net"
	"time"

	"github.com/xtaci/kcp-go/v5"
)

func main() {
	//	key := pbkdf2.Key([]byte("demo pass"), []byte("demo salt"), 1024, 32, sha1.New)
	//	block, _ := kcp.NewAESBlockCrypt(key)
	if listener, err := kcp.Listen("localhost:11000"); err == nil {
		// spin-up the client
		//go client()
		for {
			fmt.Println("awaiting connection")
			s, err := listener.Accept()

			if err != nil {
				log.Fatal(err)
			}
			go handleEcho(s)
		}
	} else {
		log.Fatal(err)
	}
}

// handleEcho send back everything it received
func handleEcho(conn net.Conn) {
	fmt.Println("new client")
	buf := make([]byte, 4096)
	for {
		n, err := conn.Read(buf)

		fmt.Println("read!!")
		if err != nil {
			log.Println(err)
			return
		}

		n, err = conn.Write(buf[:n])
		if err != nil {
			log.Println(err)
			return
		}
	}
}

garlen-javier avatar May 01 '21 15:05 garlen-javier

Test OK 20210502003112

limpo1989 avatar May 01 '21 16:05 limpo1989

Weird I always get this error while yours working, any idea why this happened?

not_work

Edit: Already tried changing port but still same

garlen-javier avatar May 01 '21 17:05 garlen-javier

Oh found the fix! I just remove the ip address in golang server and just leave the port number just like this ":11000" and it works, not sure what's the difference as I'm fairly new to backend stuff. Btw does this project ready for production use in unity3D?

garlen-javier avatar May 01 '21 17:05 garlen-javier

Oh found the fix! I just remove the ip address in golang server and just leave the port number just like this ":11000" and it works, not sure what's the difference as I'm fairly new to backend stuff. Btw does this project ready for production use in unity3D?

Im facing the same problem as yours.And I follow your fix to remove the ipAddress,it works. Have you try encryption or serialize?

MouseChannel avatar Sep 05 '21 04:09 MouseChannel