核心提示:programTestPort; uses WinSock,windows; var s:TSocket; wsd:TWSAData; SockAddrIn:TSockAddrIn; begin if...
program TestPort; uses
WinSock,windows;
var
s : TSocket;
wsd : TWSAData;
SockAddrIn : TSockAddrIn;
begin
if (WSAStartup(MAKEWORD(2,2),wsd) = 0) then
begin
s := Socket(AF_INET,SOCK_DGRAM,0);
try
if (s <> SOCKET_ERROR) then
begin
SockAddrIn.sin_family := AF_INET;
SockAddrIn.sin_addr.S_addr := htonl(INADDR_ANY);
SockAddrIn.sin_port := htons(Short(2222));
if (Bind(s,SockAddrIn,SizeOf(SockAddrIn))<>0) then
if (GetLastError = WSAEADDRINUSE) then
MessageBox(0,'Port 2222 Be Using!','Sorry',MB_OK);
end;
finally
CloseSocket(s);
WSACleanup();
end;
end;