accept运行一段时间后报access violation at address 错误????

ZHENG017 2003-09-23 04:45:03
源程序为:
var
aAddrLen:integer;
pSocketAddr:PSockAddr;
begin
GetMem(pSocketAddr,sizeof(TSockAddr));
aAddrLen:=sizeof(TSockAddr);
AcceptedConnect:=Accept(theListenSocket,pSocketAddr,@aAddrLen);
在压力测试时过大约一小时就会报
project xxx.exe raised execption class EAcsessViolation with message 'access violation at address 74f91299 in module 'wshtcpip.dll'.read of address '00000000'.process stopped.use step or run to continue;
高手多指教一下。谢谢 。
...全文
37 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
cg1120II 2003-09-23
program tcpserver;

{$APPTYPE CONSOLE}

uses
SysUtils, Windows,
winsock;

var
s,newsock:TSocket;
ser_addr:TSockAddrIn;
remote_addr:PSockAddr;
leng:Integer;
wsa:WSAData;
wVersionRequested:WORD;
buf:array[0..128]of char;
buf2:array[0..128]of char;
begin
//new(leng);
wVersionRequested := MAKEWORD( 2, 0 );
WSAStartup(wVersionRequested,wsa);
s := socket(AF_INET,SOCK_STREAM,0);
ser_addr.sin_family := AF_INET;
ser_addr.sin_addr.S_addr := htonl(INADDR_ANY);
ser_addr.sin_port := htons(4000);

bind(s,ser_addr,sizeof(ser_addr));

listen(s,0);
while 1>0 do
leng:= sizeof(remote_addr);
newsock := accept(s,remote_addr,@leng);
begin
if recv(newsock,buf,sizeof(buf),0)>0 then
begin
writeln('Client Data:',buf);
Readln(buf2);
send(newsock,buf2,sizeof(buf2),0);
end;
closesocket(newsock);
end;

closesocket(s);
WSACleanup();
sleep(2000);
end.
回复
cg1120II 2003-09-23
试试:
AcceptedConnect:=Accept(theListenSocket,pSocketAddr,PInteger(aAddrLen));
回复
相关推荐
发帖
网络通信/分布式开发
创建于2007-08-02

1573

社区成员

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