客户端创建socket失败,求解 5C

#pragma comment(lib,"ws2_32.lib")
#include
#include
#include
void main(int argc,char *argv[])
{
WSADATA wsaData;
SOCKET s;
SOCKADDR_IN ServerAddr;
int Ret;
int Port = 5150;

if(argc <= 1)
{
    printf("USAGE:TCPClient <Server IP address>.\n");
    system("pause");
    return;
}


if((Ret = WSAStartup(MAKEWORD(2,2),&wsaData)) != 0)
{
    printf("WSAData failed with error %d\n",Ret);
    return;
}
//创建新的Socket
if((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))=INVALID_SOCKET)
{
    printf("socket failed with error %d\n",WSAGetLastError());
    WSACleanup();
    return;
}
//连接
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(Port);
ServerAddr.sin_addr.S_un.S_addr = inet_addr(argv[1]);
printf("We are btrying to connect to %s:%d...\n",inet_ntoa(ServerAddr.sin_addr),htons(ServerAddr.sin_port));
if((connect(s,(SOCKADDR*)&ServerAddr,sizeof(ServerAddr))==SOCKET_ERROR))
{
    printf("connect failed with error %d\n",WSAGetLastError);
    closesocket(s);
    WSACleanup();
    return;
}
printf("our connect succeeded.\n");
printf("we will now try to send a 'Hello' massage.\n");
if((Ret = send(s,"Hello",5,0))== SOCKET_ERROR)
{
    printf("send failed with error %d\n",WSAGetLastError);
    closesocket(s);
    WSACleanup();
    return;
}

printf("We successfully sent %d bytes.\n",Ret);
printf("We are closing the connection.\n");
closesocket(s);
WSACleanup();
system("pause");

}

2个回答

if((s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==INVALID_SOCKET)
{
printf("socket failed with error %d\n",WSAGetLastError());
WSACleanup();
return;
}
两个等号

是==不是=;这是常识性错误了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!