[Ubuntu-zh] 在本机上测试Socket程序,Client提示Connect():Invalid argument

Amon Hen zzlongtk在gmail.com
星期三 十二月 15 14:27:59 GMT 2010


ÎÊÌâÒѽâ¾ö.....Õæ‡å...........

ÔÚ 2010Äê12ÔÂ15ÈÕ ÏÂÎç8:56£¬Amon Hen <zzlongtk在gmail.com>дµÀ£º

> ÈçÌâ
> googleºóµÃµ½ÐÅÏ¢£º
> WSAEINVAL
> (10022)
> Invalid argument.
> Some invalid argument was supplied (for example, specifying an invalid
> level to the setsockopt function).
>  In some instances, it also refers to the current state of the socket or
> instance, calling accept on a socket that is not listening.
>
> ÓÚÊǼì²éServer£¬telnet³É¹¦
> Åųýд´íIP¡¢¶Ë¿ÚÒ»ÀàµÄ´íÎó£¬ÄÇôÎÊÌâ³öÔÚÄÄÄØ£¿
> shellÏÂÊäÈ룺./Client 127.0.0.1 "Hi" 2000
> ºóÃæÕâ¸ö2000ÊÇ·þÎñ¶Ë¿Ú
> ÏÂÃæÊÇClientµÄ´úÂ룬´ó¼ÒÓпյϰ°ïæ¿´Ò»ÏÂ....³õѧSocket±à³Ì.....ллÁË
> int main(int argc,char *argv[])
> {
>   if (argc != 3 && argc !=4 )
>     DieWithUseMessage("Parameter(s)","<Server Address> <Echo Word> [<Server
> Port>]");//Õâ¸öÊÇÊä³öº¯Êý....
>
>   char *servIP = argv[1];
>   char *echoString = argv[2];
>
>   in_port_t servPort = (argc == 4) ? atoi(argv[3]) : 7;
>
>   int sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
>   if (sock < 0)
>     DieWithSystemMessage("socket() failed");
>
>   struct sockaddr_in servAddr;
>   memset(&servAddr,0,sizeof(servAddr));
>   servAddr.sin_family = AF_INET;
>
>   int rtnVal = inet_pton(AF_INET,servIP,&servAddr.sin_addr.s_addr)£»
>
>   if (rtnVal == 0)
>     DieWithUseMessage("inet_pton() failed","invalid address string");
>   else if (rtnVal < 0)
>     DieWithSystemMessage("inet_pton() failed");
>   servAddr.sin_port = htons(servPort);
>
>   if (connect(sock,(struct sockaddr*) &servAddr, sizeof(servAddr) <0))
>     DieWithSystemMessage("connect() failed");//¾ÍÊÇÕâ³ö´íÁË.......
> ............
> }
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20101215/85e4ca18/attachment.htm 


关于邮件列表 ubuntu-zh 的更多信息