请高手指教!如何通过serversocket组件发送p:array[0..100,0..5] of string 中的数据?(100分)

  • 主题发起人 主题发起人 _ghost
  • 开始时间 开始时间
G

_ghost

Unregistered / Unconfirmed
GUEST, unregistred user!
如何通过serversocket组件发送p:array[0..100,0..5] of string 中的数据?
请高手指教!
 
unit Unit1;

interface

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

type
TForm1 = class(TForm)
cs: TClientSocket;
ss: TServerSocket;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ssClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
buf:array[0..100,0..5] of string[255];
pbuf:pchar;
alllen:integer;
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
p:array[0..100,0..5] of string[255];
i,j:integer;
begin
pbuf:=@buf;
for i:=0 to 100 do
for j:=0 to 5 do
begin
p[i,j]:=inttostr(i)+':'+inttostr(j);
end;
cs.Socket.SendBuf(p,sizeof(p));
end;

procedure TForm1.ssClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
socket.ReceiveBuf(pbuf^,socket.ReceiveLength );
inc(pbuf,socket.ReceiveLength);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 100 do
for j:=0 to 5 do
begin
memo1.Lines.Add(buf[i,j]);
end;
end;

end.
 
很好,谢谢!
 
inc(pbuf,socket.ReceiveLength);
为什么要增加?
 
buf存储接收数据的数组,但数据不是一次传输完成的,所以用pbuf来指示
新来的数据存放在buf的什么位置
 
后退
顶部