1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
type
TypeResep=record
Typ,Tail:integer;
end;
TPMYSocket=^TMYSocket;
TMYSocket=record
Entet:TypeResep;
Resu:Integer;
Socket:TCustomWinSocket;
Strm:TMemoryStream;
Delait:DWORD;
end;
Function TForm4.EnvoitArticle;
var
sock:TPMYSocket;
strm:TMemoryStream;
begin
strm:=TMemoryStream.Create;
try
LocalCD.SaveToStream(strm);
sock.Entet.Typ:=1;
sock.Entet.Tail:=strm.size;
sock.Socket.SendBuf(t,sizof(sock.Entet));
Sleep(1);
sock.Socket.SendStream(strm);
finally
strm.Free;
end;
end;
//*******************
//***** cote reception
//*********
procedure TForm4.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
buf:TBuff; //TBuff=PIntegerArray;
i,j,p:Integer;
t:SYSTEMTIME;
s,m:string;
begin
if Local.Entet.Typ<0 then
begin
Socket.ReceiveBuf(local.Entet,sizeof(local.Entet));
Local.Strm:=TMemoryStream.Create;
exit;
end;
if local.Entet.Typ=0 then
begin
ShowMessage('OK');
Initialise;
exit;
end;
if local.Entet.Typ=20 then
begin
socket.ReceiveBuf(t,sizeof(t));
inc(t.wHour);
SetLocalTime(t);
Initialise;
exit;
end;
local.Delait:=GetTickCount;
i:=socket.ReceiveLength;
if i>0 then
begin
if i>0 then
begin
j:=Socket.ReceiveBuf(buf^,i);
Local.Strm.Read(buf^,j);
FreeMem(buf,i);
local.resu:=local.resu+j;
end;
if local.Entet.Tail=local.Resu then
begin
ClientDataSet1.LoadFromStream(local.Strm); ClientDataSet1.EnableControls;
Initialise;
end;
end; |
Partager