Home > Software engineering >  The socket server recv () 10038 mistakes
The socket server recv () 10038 mistakes

Time:09-22

 struct regular regularinfo; 

Bool Server: : initServer (ZTcpSocket * socket)
{
Server. The bind (" 172.11.2.50 ", 1111);
Server. Listen (5);
If (server. Accept (socket))
{
return true;
}
}


Bool simfun: : initsim (ZTcpSocket * socket)
{

While (1)
{

If (socket - & gt; Readable (1000)==0)
continue;
Int ret=socket - & gt; Read (buff, sizeof (regular));
If (ret<=0)
{
continue;

}
Memcpy (& amp; Regularinfo, buff, sizeof (regularinfo));
If (((regularinfo. BEG==BEG) & amp; & (regularinfo. END==END)) & amp; & ((regularinfo. CODE==C_RCU_NA_3) | | (regularinfo. CODE==C_RFB_NA_3)))
{
If (regularinfo. CODE==C_RCU_NA_3)
{
Pd=0;
cout<" Pd=0 ";
}
The else
{
Pd=1;
cout<" Pd=1 ";
}
Memset (buff, 0, sizeof (buff));
Regularinfo. CODE=M_CON_NA_3;
Memcpy (buff, & amp; Regularinfo, sizeof (regularinfo));
Ret=socket - & gt; Write (buff, sizeof (regularinfo));
cout<" Sent "& lt; break;
}
Memset (buff, 0, sizeof (buff));

}
Memset (buff, 0, sizeof (buff));
return true;

}

Bool simfun: : initsimu (ZTcpSocket * socket)
{
if (! Initsim (socket))
{
cout<" Initialization error - the main communication unit ";
}
cout<" Initialization process unit - the main communication success "& lt; While (1)
{
Here the red="int ret1=socket - & gt; Read (buff, sizeof (regular));
coutIf (ret1 & lt;=0)
{
The switch (WSAGetLastError ())
{
Case WSANOTINITIALISED: printf (" not initialized \ n "); break;
Case WSASYSNOTREADY: printf (" sub sys not ready \ n "); break;
Case WSAHOST_NOT_FOUND: printf (" name server has not found \ n "); break;
Case WSATRY_AGAIN: printf (" server fail \ n "); break;
No recovery case WSANO_RECOVERY: printf (" \ n "); break;
Case WSAEINPROGRESS: printf (" socket blocked by other prog \ n "); break;
Case WSANO_DATA: printf (" no data record \ n "); break;
Case WSAEINTR: printf (" blocking call canciled \ n "); break;
Case WSAEPROCLIM: printf (" limit exceeded \ n ");
Case WSAEFAULT: printf (" lpWSAData startup in not valid \ n ");
Default: printf (" unknown error id=% d \ n ", WSAGetLastError ()); break;
};
continue;
}

. Omit
}


The main. CPP
Void main ()
{
The Server s;
Simfun sim.
Sim. The socket=new ZTcpSocket;
S.i nitServer (sim) socket);
Sim. Initsimu (sim. The socket);
.
Omit



}



Xiaodi bucai wrote a simulator in the place where the red reading anything less than the return value is 1 getlasterror returns 10038
Each great god novice solving just write a simple single why socket connection is broken

CodePudding user response:

Front is sending and receiving normal socket can be used to add the red in 10038

CodePudding user response:

This is an invalid socket, you did not accept, also did not connect, can recv, you are a great god

CodePudding user response:

This is an invalid socket, you did not accept, also did not connect, can recv to data message, you are the great god

CodePudding user response:

refer to the second floor shenyi0106 response:
this is an invalid socket, you didn't accept, also did not connect, can recv, you are a great god
in front of the great god why can charge can send

CodePudding user response:

connection-oriented Socket Server

CodePudding user response:

Accept to write inside the while loop

CodePudding user response:

WSAENOTSOCK
(10038)
A Socket operation on non - Socket.
An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket, or for the select, a member of the An fd_set was not valid.
  • Related