采用tidudpserver和tidudpclient进行通讯

客户端:

      client.Host:='192.168.0.104';
      client.Port:=8010;
      client.Send('abc');

 

服务端:

procedure Tudpform.myudpserverUDPRead(AThread: TIdUDPListenerThread;   const AData: TIdBytes; ABinding: TIdSocketHandle); var  stream:tmemorystream;  total1,curpak,sumpak:word;  filetype:integer;  fileindex:integer;  str:string;  sdata:tidbytes;  abd:TIdSocketHandle; begin   inc(total);   tempbinding:=abinding;

  curpak:=adata[7]*256*256*256+adata[8]*256*256+adata[9]*256+adata[10];   sumpak:=adata[11]*256*256*256+adata[12]*256*256+adata[13]*256+adata[14];   caption:=format('total:%d,sumpak:%d,curpak:%d',[total,sumpak,curpak]);

  stream:=tmemorystream.Create;   stream.Write(adata[0],high(adata)+1);   udpclients.netdata.AddDatas(athread.Binding.PeerIP,athread.Binding.PeerPort,stream);   setlength(sdata,4);   sdata[0]:=48;   sdata[1]:=49;   sdata[2]:=50;   sdata[3]:=51;   myudpserver.binding.assign(abinding);   abinding.SendTo(abinding.PeerIP,abinding.PeerPort,sdata);

  //myudpserver.SendBuffer(abinding.PeerIP,abinding.PeerPort,sdata);   //udpclients.ProcessUdpData(athread,adata,abinding);

end;

posted @ 2014-08-14 11:07  LAOS  阅读(1540)  评论(0编辑  收藏  举报