我必须连接到host
和port
。端口是常量,但host
变量应该从 shell 输入。我有一个错误。
int main(int argc, char ** argv)
{
if (argc<2){
printf("Need more arguments\n");
return 1;
}
int sock;
if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0){
perror("socket creating error");
return 1;
}
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(22222);
addr.sin_addr.s_addr = argv[1]; // try to conect host
...
}