Esempio n. 1
0
        public Packed Recieve()
        {
            if (!Setup)
            {
                return(new Packed());
            }
            Packed buff  = new Packed();
            int    psize = BitConverter.ToInt32(NetCat.ReceiveBytes(sizeof(int)), 0);

            byte[] arr  = NetCat.ReceiveBytes(psize);
            int    size = Marshal.SizeOf(buff);

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.Copy(arr, 0, ptr, size);

            buff = (Packed)Marshal.PtrToStructure(ptr, buff.GetType());
            Marshal.FreeHGlobal(ptr);
            return(buff);
        }
Esempio n. 2
0
        public void Send(Packed packed)
        {
            if (!Setup)
            {
                return;
            }

            int size = Marshal.SizeOf(packed);

            byte[] arr = new byte[size];

            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(packed, ptr, true);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);


            int ss = arr.Length;

            NetCat.SendBytes(BitConverter.GetBytes(ss));
            NetCat.SendBytes(arr);
        }