如何传输一个结构?(100分)

  • 主题发起人 主题发起人 jingtao
  • 开始时间 开始时间
J

jingtao

Unregistered / Unconfirmed
GUEST, unregistred user!
如果比较小,比如说1024就无问题
否则出错
如何解决?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;

const iSize=2324;
type
TVideoParkFrame=record
sign:array[0..3] of char;//标志
data:PByte;//数据
end;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ServerSocket1: TServerSocket;
ClientSocket1: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
VideoParkFrame1:TVideoParkFrame;
VideoParkFrame2:^TVideoParkFrame;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
const Abc:array[0..5] of byte=(9,1,1,1,1,1);
begin
VideoParkFrame1.sign[0]:='p';
VideoParkFrame1.data:=@Abc;
ClientSocket1.Socket.SendBuf(VideoParkFrame1,iSize);
end;

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
Socket.ReceiveBuf(VideoParkFrame2^,iSize);
Memo1.Lines.Add(inttostr(VideoParkFrame2^.data^));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
new(VideoParkFrame2);
VideoParkFrame2^.data:=GetMemory(1024);
end;

end.
 
建议改为Indy控件,和流传输方式,因为TServerSocket和TClientSocket十分不稳定
 
用TCP不应该有问题呀,另外你可以在报文首部指明数据的长度
 
多人接受答案了。
 

Similar threads

后退
顶部