procedure TForm1.Button1Click(Sender: TObject);
var
bName:array [0..255]of char;
wd:TWsadata;
myhost
HostEnt;
ipstr:string;
sdr
sockaddr;
sock:Tsocket;
ru:integer;
buf:string;
pt:int64;
fs:Tfilestream;
filectrl,ReturnCtrl:TfileCT;
s:string;
bufs,return:array [0..3212] of byte;
begin
try
ru:=wsastartup(makeword(2,2),wd); //初始化sock库
if ru<>0 then
begin
exit;
self.writelog('WSAstartup Error');
end;
//gethostname(@bname,256); //取得pcname
//myhost:=gethostbyname(@bname); //取得地址信息
//ipstr:=inet_ntoa(Pinaddr(myhost.h_address_list^)^);//取得pcIP地址
sdr:=new(psockaddr);
sdr.sin_addr.S_addr:=inet_addr(Pchar(trim(edit3.Text)));
sdr.sin_family:=2;
sdr.sin_port:=htons(27815);
sock:=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if sock=INVALID_SOCKET then
begin
self.writelog('Socket Error');
exit;
end;
ru:=connect(sock,sdr,sizeof(Tsockaddr));
// RU:=sendto();
if ru=SOCKET_ERROR then
begin
self.writelog('connect 连接失败');
exit;
end;
try
fs:=TfileStream.Create(edit2.Text,fmopenread);
pt:=0;
while true do
begin
if pt>=fs.Size then break;
zeromemory(@filectrl,sizeof(TfileCT));
copymemory(@filectrl.cmd[0],pchar('SF'),2);
copymemory(@filectrl.path[0],pchar('/s1/'),sizeof(pchar('/s1/')));
s:=pchar(extractfileName(trim(edit2.Text)));
copymemory(@filectrl.fn[0],pchar(s),length(s));
filectrl.DataPoint:=pt;
if (fs.Size-pt)>(3212-sizeof(TfileCT)) then
begin
filectrl.dataSize:=3212-sizeof(TfileCT);
end else
begin
fileCtrl.dataSize:=fs.Size-pt;
end;
zeromemory(@bufs[0],sizeof(bufs));
copymemory(@bufs[0],@filectrl,sizeof(TfileCT));
fs.Position:=0;
fs.Seek(pt,0);
fs.ReadBuffer(bufs[sizeof(TfileCT)],filectrl.dataSize);
send(sock,bufs,sizeof(bufs),0);
self.writelog('send file'+edit2.Text+' '+inttostr(filectrl.DataPoint)+' '+inttostr(filectrl.dataSize));
zeromemory(@return[0],sizeof(return));
recv(sock,return,sizeof(return),0);
copymemory(@returnCtrl,@return[0],sizeof(TfileCt));
pt:=pt+returnctrl.dataSize;
self.writelog('send file'+edit2.Text+' '+inttost
(returnCtrl.DataPoint)+' '+inttostr(returnCtrl.dataSize));
end;
except
self.writelog('false');
end;
finally
dispose(sdr);
closesocket(sock);
WSAcleanup();
self.writelog('WSAcleanup');
end;
end;
//==============================================
现在是必须关闭客户端才能立刻再次连接服务器,
传输过程没问题的,
应该是客户端的问题,哪位老大能帮我看看?