Y
youjq
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);
type TDebugDL = record
Parm1:String;
Parm2:String;
Parm3:String;
Parm4:String;
Parm5:String;
Parm6:String;
Parm7:String;
end;
var
FSyn_Buf: array[0..2] of char;
TheStream: TWinSocketStream;
ClientSocket: TClientSocket;
iPkglen: integer;
iTotalPkg: Word;
DebugDL: TDebugDL;
begin
DebugDL.Parm1:=Format('%-6s',['010200']);
DebugDL.Parm2:=Format('%-6s',['335615']);
DebugDL.Parm3:=Format('%-10s',['100120130']);
DebugDL.Parm4:=Format('%-8s',['']);
DebugDL.Parm5:=Format('%-2s',['']);
DebugDL.Parm6:=Format('%-2s',['02']);
DebugDL.Parm7:=Format('%-5s',['96528']);
FSyn_Buf[0] := #2;
FSyn_Buf[1] := #0;
FSyn_Buf[2] := #0;
iPkglen:= sizeof(DebugDL); //数据包长度
iTotalPkg:= htons(word(iPkglen)); <font color=red>(*为什么运行到这句要发生错误*)</font>
//建立连接
ClientSocket:= TClientSocket.Create(nil);
TheStream:= TWinSocketStream.Create(ClientSocket.Socket,6000);
ClientSocket.ClientType:= ctBlocking;
ClientSocket.Address:= '172.16.2.1';
ClientSocket.Port :=3000;
ClientSocket.Open;
TheStream.Write(FSyn_Buf,4); //发包头
TheStream.Write(iTotalPkg,2); //发长度
// TheStream.Write(htons(iTotalPkg),2); //发内容
FillChar(Buffer1, 5, 0);
if TheStream.WaitForData(6000) then begin
TheStream.Read(Buffer1,4);
for i:=0 to 5-1 do //前4位是包的长度
strRec:=strRec+Buffer1;
showmessage(strRec);
end;
end;
type TDebugDL = record
Parm1:String;
Parm2:String;
Parm3:String;
Parm4:String;
Parm5:String;
Parm6:String;
Parm7:String;
end;
var
FSyn_Buf: array[0..2] of char;
TheStream: TWinSocketStream;
ClientSocket: TClientSocket;
iPkglen: integer;
iTotalPkg: Word;
DebugDL: TDebugDL;
begin
DebugDL.Parm1:=Format('%-6s',['010200']);
DebugDL.Parm2:=Format('%-6s',['335615']);
DebugDL.Parm3:=Format('%-10s',['100120130']);
DebugDL.Parm4:=Format('%-8s',['']);
DebugDL.Parm5:=Format('%-2s',['']);
DebugDL.Parm6:=Format('%-2s',['02']);
DebugDL.Parm7:=Format('%-5s',['96528']);
FSyn_Buf[0] := #2;
FSyn_Buf[1] := #0;
FSyn_Buf[2] := #0;
iPkglen:= sizeof(DebugDL); //数据包长度
iTotalPkg:= htons(word(iPkglen)); <font color=red>(*为什么运行到这句要发生错误*)</font>
//建立连接
ClientSocket:= TClientSocket.Create(nil);
TheStream:= TWinSocketStream.Create(ClientSocket.Socket,6000);
ClientSocket.ClientType:= ctBlocking;
ClientSocket.Address:= '172.16.2.1';
ClientSocket.Port :=3000;
ClientSocket.Open;
TheStream.Write(FSyn_Buf,4); //发包头
TheStream.Write(iTotalPkg,2); //发长度
// TheStream.Write(htons(iTotalPkg),2); //发内容
FillChar(Buffer1, 5, 0);
if TheStream.WaitForData(6000) then begin
TheStream.Read(Buffer1,4);
for i:=0 to 5-1 do //前4位是包的长度
strRec:=strRec+Buffer1;
showmessage(strRec);
end;
end;