int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user) { byte[] buff = new byte[len]; Marshal.Copy(new IntPtr(buf), buff, 0, len); udpsocket.SendTo(buff, 0, len, SocketFlags.None, remoteipep); return(0); }
protected virtual int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user) { byte[] kcppack = new byte[len]; Marshal.Copy(new IntPtr(buf), kcppack, 0, len); #if PRINTPACK Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}"); #endif var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length]; defpb.Write(sendbuf, kcppack, 0, kcppack.Length); OutgoingData.Enqueue(sendbuf); return(0); }
protected override unsafe int udp_output(byte *buf, int len, k.IKCPCB *kcp, void *user) { //一定是reliable byte[] kcppack = new byte[len + 1]; Marshal.Copy(new IntPtr(buf), kcppack, 1, len); kcppack[0] = (byte)PackType.Kcp; #if PRINTPACK Console.WriteLine($"kcp_output:size{kcppack.Length}:{string.Join(",", kcppack)}"); #endif var sendbuf = new byte[PackSettings.HEADER_LEN + kcppack.Length]; defpb.Write(sendbuf, kcppack, 0, kcppack.Length); OutgoingData.Enqueue(sendbuf); return(0); }
private unsafe void button_init_Click(object sender, EventArgs e) { var userid = uint.Parse(textBox_sid.Text); var arr = textBox_local.Text.Split(":"[0]); localipep = new IPEndPoint(IPAddress.Parse(arr[0]), int.Parse(arr[1])); arr = textBox_remote.Text.Split(":"[0]); remoteipep = new IPEndPoint(IPAddress.Parse(arr[0]), int.Parse(arr[1])); kcp1 = ikcp_create(userid, (void *)userid); kcp1->output = Marshal.GetFunctionPointerForDelegate(new k.d_output(udp_output)); ikcp_wndsize(kcp1, 128, 128); ikcp_nodelay(kcp1, 1, 10, 2, 1); kcp1->rx_minrto = 10; kcp1->fastresend = 1; udpsocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); udpsocket.Blocking = false; udpsocket.Bind(localipep); }