socket编程的小小问题 我在arm开发板下用c实现了send一些字符,在Linux下的c可以收到,但是我在delphi下用recv函数为什么就收不到第一位的字符呢?还望各位赐教啊!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 贴下你接收的代码recv函数接收的数据长度对不对? 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);beginclose;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);varbuf:shortstring;begin recv(client,buf,9,0); dushu.Text:=buf; closesocket(client);end;end.这是全部代码! 交叉试验你在delphi下用recv函数,能收到其它发送者发出的信息吗? 从代码中看不出问题,你用INDY的TCPServer试试,估计是你用API编程有问题。 delphi 创建多线程 如何用delphi实现类似XP的标题栏? 這個題目怎麼做?(一) 还记得在delphi中的关于对话框中当你按下几个键后就可以自动运行另一个程序吗?他是如何实现的呢? 使用Delphi8做ASP.Net程式,发规Inetinfo.exe占用内存特别大,为什么? fastreport问题,在线等,高分!!!!!!!!!!! 谁能给我提个建议? 请问在2000下怎么屏蔽系统键 请教ado问题,急! !!!打印问题 delphi2007怎么不能转换utf8编码啊 delphi7中如何传送数据?
recv函数接收的数据长度对不对?
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.
这是全部代码!
你在delphi下用recv函数,能收到其它发送者发出的信息吗?