问题已解决.....真��...........
在 2010年12月15日 下午8:56,Amon Hen <[email protected]>写道:
> 如题
> 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 mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh