Delphi的socket通信 服务器向客户端发数据,程序如下,哪位大神指指哪错了,客户端接收不到数据 20
procedureTForm1.Button2Click(Sender:TObject);varca:SOCKADDR_IN;ra:SOCKADDR_IN;hostadd...
procedure TForm1.Button2Click(Sender: TObject);
var
ca:SOCKADDR_IN;
ra:SOCKADDR_IN;
hostaddr:u_long;
BlockNum, RemainLen: integer;
BlockBuf3: array[0..Blocklen-1] of Byte;
i,j: integer;
SendLen,ra_len,recelen,sum: integer;
recvSocket: TSocket;
BlockBuf2:array[0..Blocklen-1] of Byte;
begin
RemainLen := 175;
InTrans :=True;
SendLen :=0;
if RemainLen >0 then
begin
Server:=strtoint(form1.label2.Caption);
for i:=0 to 163 do //16个字节
begin
for j:=0 to 4 do
BlockBuf3[i*5+j]:=i;
end;
BlockBuf3[0]:=$A5;
BlockBuf3[1]:=$5A;
BlockBuf3[2]:=strtoint(form1.Edit2.text);
BlockBuf3[3]:=strtoint(form1.Edit3.text);
BlockBuf3[4]:=strtoint(form1.Edit4.text);
BlockBuf3[5]:=strtoint(form1.Edit5.text);
BlockBuf3[6]:=strtoint(form1.Edit6.text);
BlockBuf3[7]:=strtoint(form1.Edit7.text);
BlockBuf3[8]:=strtoint(form1.Edit8.text);
BlockBuf3[9]:=strtoint(form1.Edit9.text);
sum:=0;
//for i:=10 to 163 do
// BlockBuf1[i]:=$FF;
//sum:=sum+BlockBuf1[i];
BlockBuf3[164]:=$FF;
BlockBuf3[165]:=$FF;
BlockBuf3[166]:=$FF;
BlockBuf3[167]:=$FF;
BlockBuf3[168]:=$FF;
SendLen := send(Server, BlockBuf3,RemainLen, 0);
if (SendLen <=0 ) then
begin
inTrans := false;
form1.StatusBar1.SimpleText := '系统异常终止';
end;
end;
intrans := false;
form1.StatusBar1.SimpleText := '传输完成';
end; 展开
var
ca:SOCKADDR_IN;
ra:SOCKADDR_IN;
hostaddr:u_long;
BlockNum, RemainLen: integer;
BlockBuf3: array[0..Blocklen-1] of Byte;
i,j: integer;
SendLen,ra_len,recelen,sum: integer;
recvSocket: TSocket;
BlockBuf2:array[0..Blocklen-1] of Byte;
begin
RemainLen := 175;
InTrans :=True;
SendLen :=0;
if RemainLen >0 then
begin
Server:=strtoint(form1.label2.Caption);
for i:=0 to 163 do //16个字节
begin
for j:=0 to 4 do
BlockBuf3[i*5+j]:=i;
end;
BlockBuf3[0]:=$A5;
BlockBuf3[1]:=$5A;
BlockBuf3[2]:=strtoint(form1.Edit2.text);
BlockBuf3[3]:=strtoint(form1.Edit3.text);
BlockBuf3[4]:=strtoint(form1.Edit4.text);
BlockBuf3[5]:=strtoint(form1.Edit5.text);
BlockBuf3[6]:=strtoint(form1.Edit6.text);
BlockBuf3[7]:=strtoint(form1.Edit7.text);
BlockBuf3[8]:=strtoint(form1.Edit8.text);
BlockBuf3[9]:=strtoint(form1.Edit9.text);
sum:=0;
//for i:=10 to 163 do
// BlockBuf1[i]:=$FF;
//sum:=sum+BlockBuf1[i];
BlockBuf3[164]:=$FF;
BlockBuf3[165]:=$FF;
BlockBuf3[166]:=$FF;
BlockBuf3[167]:=$FF;
BlockBuf3[168]:=$FF;
SendLen := send(Server, BlockBuf3,RemainLen, 0);
if (SendLen <=0 ) then
begin
inTrans := false;
form1.StatusBar1.SimpleText := '系统异常终止';
end;
end;
intrans := false;
form1.StatusBar1.SimpleText := '传输完成';
end; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询