當前位置:編程學習大全網 - 網站源碼 - linux socket中的connect無法連接

linux socket中的connect無法連接

中間加幾個調試語句

struct hostent *ho=gethostbyname(url);

if (!ho) fprintf(stderr, "WRONG URL\n");

in.sin_addr.s_addr=((unsigned long *)(ho->h_addr_list[0]))[0];

fprintf(stderr, "ip = %s\n", inet_addr(in.sin_addr.s_addr));

in.sin_family=ho->h_addrtype;

in.sin_port=htons(1234);

connect(sock,(struct sockaddr*)&in,sizeof(in));

妳看看解釋出來的IP地址對不對,然後用telnet ip 1234試試

  • 上一篇:Dnf黑火山刷攻略刷黑火山金怎麽玩?
  • 下一篇:百世文華錄通用禮包碼有哪些?
  • copyright 2024編程學習大全網