udp编程中,server端老是接受不到数据?帮忙看一下.[菜鸟问题]

hoooh_hob 2003-05-20 10:09:14
程序如下:
client端:
var
wsaData:TWSAData;
sock:Tsocket;
client,server:TsockAddr;
re:integer;
Pbuf:pchar;
sbuf:string;
i:integer;

beg in
if (WSAStartup(2,wsadata)<>0) then
writeln('wsastartup error');
sock:=socket(AF_INET,SOCK_DGRAM,0);
if (sock=INVALID_SOCKET) then
writeln('sock error');

writeln('kaka');
pbuf:='this is a test';


server.sin_family:=AF_INET;
server.sin_port :=htons(6666);
server.sin_addr.S_addr:=inet_addr(pchar('202.200.xxx.88'));

for i:= 1 to 20 do
begin
sendto(sock,pbuf^,length(pbuf),0,server,sizeof(server));
writeln('send');
sleep(1000);
end;

closesocket(sock);
wsacleanup();

end.

=============================================================
server端:
var
wsaData:TWSAData;
sock:Tsocket;
client,server:TsockAddr;
re:integer;
Pbuf:pchar;
sbuf:string;
rval:integer;
len:integer;
i:integer;
begin
if (WSAStartup(2,wsadata)<>0) then
writeln('wsastartup error');
sock:=socket(AF_INET,SOCK_DGRAM,0);
if (sock=INVALID_SOCKET) then
writeln('sock error');
server.sin_family:=AF_INET;
server.sin_port:=htons(6666);
server.sin_addr.S_addr:=inet_addr('202.200.xxx.88');
re:=bind(sock,server,sizeof(server));
if (re<>0) then
writeln('bind error');

getmem(pbuf,100);
// zeromemory(pbuf,100);
writeln('here');

while(true) do //sock,pbuf^,length(pbuf),0,server,sizeof(server)
begin
rval:=recvfrom(sock,pbuf^,length(pbuf),0,client,len);
if rval>0 then
sbuf:=strpas(pbuf);
end;




wsacleanup();

end.

这个问题已经让我苦恼了很久了.
那位大虾能帮我看一下,谢谢先.

...全文
9 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yatoo 2003-06-19
关注
回复
相关推荐
发帖
网络通信/分布式开发
创建于2007-08-02

1575

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2003-05-20 10:09
社区公告
暂无公告