gpt4 book ai didi

c++ - WSAGetLastError 返回 WSAENOTSOCK - 原因?

转载 作者:行者123 更新时间:2023-11-28 03:11:54 25 4
gpt4 key购买 nike

我的代码中有这样的东西

    WSADATA wsadata;

int error = WSAStartup(0x0202, &wsadata);

SOCKADDR_IN target; //Socket address information

target.sin_family = AF_INET; // address family Internet
target.sin_port = htons (5005);
target.sin_addr.s_addr = inet_addr ("127.0.0.1");

clntSocket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); //Create socket


if (::connect(clntSocket, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
{
//Could not connect
__debugbreak();
}
else
{
//Connected - Now receive data
do
{
char my_stream[800];
iResult = recv(clntSocket,my_stream,sizeof(my_stream),0);
if(iResult<0)
{
int a = WSAGetLastError();
//Receives 10038 - WSAENOTSOCK
}
} while( iResult > 0 );
}

我有时(偶尔)会得到 10038。这表明

Socket operation on nonsocket.

An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket,or for select, a member of an fd_set was not valid.

我在设置套接字时做错了什么吗?关于如何解决问题的任何建议?

最佳答案

或者:

  1. 您从未打开过 socket 。
  2. 您损坏了句柄值。
  3. 您已关闭套接字,然后继续使用它。

关于c++ - WSAGetLastError 返回 WSAENOTSOCK - 原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18200584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com