From 1e905839f03b86d1f90702fb3595225037d84209 Mon Sep 17 00:00:00 2001 From: fatedier Date: Wed, 25 Oct 2017 03:02:25 +0800 Subject: [PATCH] update kcp connection options --- utils/net/kcp.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/utils/net/kcp.go b/utils/net/kcp.go index 4a38fc03..18979c12 100644 --- a/utils/net/kcp.go +++ b/utils/net/kcp.go @@ -87,5 +87,15 @@ func (l *KcpListener) Close() error { } func NewKcpConnFromUdp(conn *net.UDPConn, connected bool, raddr string) (net.Conn, error) { - return kcp.NewConnEx(1, connected, raddr, nil, 10, 3, conn) + kcpConn, err := kcp.NewConnEx(1, connected, raddr, nil, 10, 3, conn) + if err != nil { + return nil, err + } + kcpConn.SetStreamMode(true) + kcpConn.SetWriteDelay(true) + kcpConn.SetNoDelay(1, 20, 2, 1) + kcpConn.SetMtu(1350) + kcpConn.SetWindowSize(1024, 1024) + kcpConn.SetACKNoDelay(false) + return kcpConn, nil }