当我用tcpclient向一指定ip和端口的机器发送数据时
服务器受数据后应该返回一个数据给发送端
我怎样控制服务器的返回数据和在客户端接受这个返回数据啊

解决方案 »

  1.   

    这个组件不是有OnReceive事件吗?可以使用它啊
      

  2.   

    ---续  //***********************************************************************************************
       //脉波帧命令字 5c 53 05 01 02 A2 24 4A       (返回)
       //当主站收到 脉波帧后要给它一个信息,这样子站才能正常保持通讯状态,否则子站会重连
       //脉波帧命令字 5c530901026123450000a2244a    (发送)   if (s='8') and (inttohex(readdata[7],2)='24') and (inttohex(readdata[6],2)='A2') then
        begin
          fsmbok:=false;
          gprsid:=inttohex(readdata[5],2)+inttohex(readdata[4],2);
          //RichEdit1.Lines.Insert(0,'-----------------------------------------------------------');
          //RichEdit1.Lines.Insert(0,'捕捉到来自 ID='+gprsid+' 的脉波帧命令!'+ss);
          for k:=0 to listview1.Items.Count-1 do
            begin
              if  (listview1.Items.Item[k].SubItems.Strings[0]=gprsid) then
                begin
                  //从列表中取出一个序号 ;
                  lisno:=trim(listview1.Items.Item[k].Caption);
                  //返回给子站一个脉波帧命令;下达指令  5c530901026123450000a2244a
                  //调用计算校验和函数
                  strjyhml:=jsjyh('5C5309'+copy(gprsid,3,2)+copy(gprsid,1,2)+'6123450000A224');
                  gprsml(lisno,strjyhml);
                  fsmbok:=true;         //脉波帧命令发送成功
                end;
            end;
          if fsmbok=true then
            begin
              RichEdit1.Lines.Insert(0,'--------------------------------------------------------------------------------------');
              RichEdit1.Lines.Insert(0,'回复 ID='+gprsid+' 的脉波帧命令成功! '+datetimetostr(now));
            end
          else
            begin
              RichEdit1.Lines.Insert(0,'--------------------------------------------------------------------------------------');
              RichEdit1.Lines.Insert(0,'找不到有对应的 ID, 回复脉波帧命令不成功! '+datetimetostr(now));
            end;
        end;
      if (s='26') and (inttohex(readdata[8],2)='68') and (inttohex(readdata[17],2)='06') then
                 //这个包是含电是量的包; 要把数据包写回数据库;
        begin   //  这时还要从listview1中取得GPRS 中的 ID 号
         for k:=0 to listview1.Items.Count-1 do
            begin
              if  (listview1.Items.Item[k].SubItems.Strings[1]=socket.RemoteAddress) and(listview1.Items.Item[k].SubItems.Strings[2]=inttostr(socket.RemotePort)) then
                begin    
                  RichEdit1.Lines.Insert(0,'--------------------------------------------------------------------------------------');
                  RichEdit1.Lines.Insert(0,'来自IP:'+socket.RemoteAddress+' 在'+datetimetostr(now));
                  RichEdit1.Lines.Insert(0,'发回的数据包'+#13+'长度:'+s+#13+'内容:'+ss);              gprsid:=listview1.Items.Item[k].SubItems.Strings[0];   //给gprsid 赋值;
                  with DataModule2.ADOQuery1 do
                    begin
                      close;
                      sql.Clear;
                      sql.Add('insert into gprs_receive (id,dtime,content)');
                      sql.Add('values (:u1,:u2,:u3)');
                      Parameters.ParamByName('u1').Value:=gprsid;
                      Parameters.ParamByName('u2').Value:=now;        //Formatdatetime('yyyy-m-d',now)
                      Parameters.ParamByName('u3').Value:=sss;
                      prepared;
                      execsql;
                    end;
                  statusbar1.Panels.Items[0].Text:='抄回数据并入库!';
                  break;
                end;
            end;
        end;
    end;
      

  3.   

    看来,楼主和一楼问的是D7的TTCPClient和TTCPServer空件的用法,我做了一个CHAT程序,若感兴趣,发E-Mail到:[email protected]
    我将源码发给你们参考。
      

  4.   

    TO:gzbchina(鸽飞)是不是TTCPClient发送数据到TTCPServer
          然后由TTCPServer 返回信息到TTCPClient?如果是,请麻烦一下给一份过来[email protected]        谢谢
              
      

  5.   

    在INTERNET上还行的通么????
      

  6.   

    请XXSingle(水连天)给我发一份CHAT程序,我的E-MAIL:[email protected]
      

  7.   

    http://tech.ccidnet.com/pub/article/c1079_a29603_p1.html
      

  8.   

    cnsolonet(鹰):能不能把原程序发一份给我?[email protected]
      

  9.   

    gzbchina(鸽飞),能给我发一份程序吗?谢谢。我的E-MAIL:[email protected]