我在arm开发板下用c实现了send一些字符,在Linux下的c可以收到,但是我在delphi下用recv函数为什么就收不到第一位的字符呢?还望各位赐教啊!!

解决方案 »

  1.   

    贴下你接收的代码
    recv函数接收的数据长度对不对? 
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls, Buttons,Winsock,ExtCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Label1: TLabel;
        Label2: TLabel;
        IP: TEdit;
        dushu: TEdit;
        StatusBar1: TStatusBar;
        procedure formcreate(Sender: TObject);
        procedure formclose(Sender: TObject; var Action: TCloseAction);
        procedure Button3Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);  private
      Client:TSocket;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.formcreate(Sender: TObject);
    var
      aWSAData:TWSAData;
    begin
       if WSAStartup($0101,aWSAData)<>0 then
       raise Exception.Create('不能启动WinSock动态链接库!');
       MessageBox(Handle,aWSAData.szDesCription,'WinSock动态链接库版本',MB_OK);
     end;procedure TForm1.formclose(Sender: TObject; var Action: TCloseAction);
    begin
       if WSACleanup<>0 then
            MessageBox(Handle,'清除WinSock动态连接库错误','提示',MB_OK)
        else
            MessageBox(Handle,'清除WinSock动态连接库成功','提示',MB_OK);
            closesocket(client);
    end;procedure TForm1.Button3Click(Sender: TObject);
    begin
    close;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      ca:SOCKADDR_IN;
      hostaddr:u_long;
     begin
       client:=socket(PF_INET,SOCK_STREAM,IPPROTO_IP);
       IF Client=INVALID_SOCKET  then
       begin
        StatusBar1.simpleText:='创建socket错误!';
        exit;
       end;
        ca.sin_family:=PF_INET;
        ca.sin_port:= htons(2000);
        hostaddr:=inet_addr(pchar(trim(IP.Text)));
       if (hostaddr=-1)then
       begin
        statusbar1.SimpleText:='host ip:'+trim(IP.Text)+'error';
        exit;
       end
       else
          ca.sin_addr.S_addr:=hostaddr;
        if connect(client,ca,sizeof(ca))<>0 then
          begin
          statusbar1.SimpleText:='连接socket错误!';
          exit;
          end
          else
           statusbar1.SimpleText:='连接成功!'; end;procedure TForm1.Button2Click(Sender: TObject);
    var
    buf:shortstring;begin
     recv(client,buf,9,0);
     dushu.Text:=buf;
     closesocket(client);
    end;
    end.
    这是全部代码!
      

  3.   

    交叉试验
    你在delphi下用recv函数,能收到其它发送者发出的信息吗?
      

  4.   

    从代码中看不出问题,你用INDY的TCPServer试试,估计是你用API编程有问题。