S
subcom
Unregistered / Unconfirmed
GUEST, unregistred user!
xianguo你让我下载的是WINSOCK2。我的程序是用WINSOCK写的。就是无法接收数据。请问它和WINSOCK有什么区别吗?以下是原代码敬请指教
var
sock,len,msgsock:integer;
//sock,length,,rval,err:integer;
buf:array[0..1023]of char;
wVersionRequested:WORD;
wsaData:TWSADATA;
server:TSockAddrIn;
i,err:integer;
addrchar;
size:integer;
procedure Trec.Execute;
var x:char;
begin
sleep(100);
with form1 do begin
{ }
{wVersionRequested:=MAKEWORD(2,0);
err:=WSAStartup(wVersionRequested,wsaData);
if err<>0 then
Label1.Caption:='初始化失败!'}
if WSAStartup($0101, wsaData)<>0 then
begin
showmessage('不能初始化Winsock!');
Exit;
end
else begin
sock:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if sock=INVALID_SOCKET then
Label1.Caption:='创建套接口失败!'
else begin
server.sin_family:=AF_INET;
server.sin_port:=htons(2000);
server.sin_addr.s_addr:=inet_addr(Pchar(edit2.Text));;
if bind(sock,server,sizeof(server))<>0 then
Label1.Caption:='绑定套接口失败!';
len:=sizeof(server);
//getsockname(sock,server,len);
if listen(sock,5)<>0 then
Label1.Caption:='侦听失败!';
if accept(sock,@server,@len)=INVALID_SOCKET then
Label1.Caption:='接受失败!';
size:=1024;
i:=recv(sock,buf,size,MSG_OOB);
if i<>0 then
Label1.Caption:='接收失败!';
end
end
end;
{ Place thread code here }
end;
var
sock,len,msgsock:integer;
//sock,length,,rval,err:integer;
buf:array[0..1023]of char;
wVersionRequested:WORD;
wsaData:TWSADATA;
server:TSockAddrIn;
i,err:integer;
addrchar;
size:integer;
procedure Trec.Execute;
var x:char;
begin
sleep(100);
with form1 do begin
{ }
{wVersionRequested:=MAKEWORD(2,0);
err:=WSAStartup(wVersionRequested,wsaData);
if err<>0 then
Label1.Caption:='初始化失败!'}
if WSAStartup($0101, wsaData)<>0 then
begin
showmessage('不能初始化Winsock!');
Exit;
end
else begin
sock:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if sock=INVALID_SOCKET then
Label1.Caption:='创建套接口失败!'
else begin
server.sin_family:=AF_INET;
server.sin_port:=htons(2000);
server.sin_addr.s_addr:=inet_addr(Pchar(edit2.Text));;
if bind(sock,server,sizeof(server))<>0 then
Label1.Caption:='绑定套接口失败!';
len:=sizeof(server);
//getsockname(sock,server,len);
if listen(sock,5)<>0 then
Label1.Caption:='侦听失败!';
if accept(sock,@server,@len)=INVALID_SOCKET then
Label1.Caption:='接受失败!';
size:=1024;
i:=recv(sock,buf,size,MSG_OOB);
if i<>0 then
Label1.Caption:='接收失败!';
end
end
end;
{ Place thread code here }
end;