文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>解决ADOConnection1连接数据库假死

解决ADOConnection1连接数据库假死

时间:2010-12-29  来源:fyen

function ScanTCPPort(ipstr: string; Port: DWORD): Boolean;
var
  option: DWORD;
  TcpSock: TSocket;
  InAddr: TSockAddrIn;
  IP: DWORD;
begin
  result := False;

  //convert IP string to ulong
  IP := ntohl(inet_addr(PChar(ipstr)));
  if IP = INADDR_NONE then //invalid IP address!
    exit;

  // Create/open a socket (stream, not datagram)
  TcpSock := socket(AF_INET, SOCK_STREAM, 0);
  if TcpSock = INVALID_SOCKET then //socket error
    exit;

  try
    // Set socket options
    option := 0;
    setsockopt(TcpSock, SOL_SOCKET, SO_KEEPALIVE, @option, sizeof(option));
    option := 1;
    setsockopt(TcpSock, SOL_SOCKET, SO_DONTLINGER, @option, sizeof(option));

    //if winsock 1.1, including the next sentence, otherwise, skip it.
    setsockopt(TcpSock, IPPROTO_TCP, TCP_NODELAY, @option, sizeof(option));

    //Initialize address structure
    ZeroMemory(@InAddr, sizeof(InAddr));
    InAddr.sin_family := AF_INET;
    InAddr.sin_addr.S_addr := ntohl(IP);
    InAddr.sin_port := htons(Port);
    //Try to connect
    Result := connect(TcpSock, InAddr, sizeof(InAddr)) = 0;
  finally
    //Close the socket
    closesocket(TcpSock);
  end;
end;

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载