我正在尝试制作一个简单的套接字客户端(使用 debian 6 和 g++ 编译器),当我调用“connect”函数时,它返回错误代码 22 - Invalid argument。请告诉我,我做错了什么。
我已经阅读了这个函数的手册页,它说 3 个参数必须如下:int、struct sockaddr* 和 socklen_t。
我的代码是:
int serverPort;
u_long serverHost;
struct sockaddr_in serverAddress;
socklen_t serverAddressLength;
int clientSocket;
serverPort = 44444;
serverHost = inet_addr ( "88.198.237.65" );
serverAddress.sin_family = AF_INET;
serverAddress.sin_port = htons ( serverPort );
serverAddress.sin_addr.s_addr = htons ( serverHost );
serverAddressLength = sizeof ( serverAddress );
clientSocket = socket ( AF_INET , SOCK_STREAM , 0 );
connect ( clientSocket , (sockaddr*)&serverAddress , serverAddressLength )