c++ - Socket send recv functions -


I created the socket using the following lines of code: now I will change the value of this socket

M_Socket ++;

Still sending socket function succeeds without throwing SOCKET_ERROR. I hope it has to throw the error.

Am I doing something wrong?

struct sockaddr_in ServerSock; // Socket Address Structure To bind port number

  char * localIP; Socket socketer; // sockaddr structure to set up ServerSock.sin_family = AF_INET; ServerSock.sin_addr.s_addr = INADDR_ANY; ServerSock.sin_port = htons (pLantronics-> m_wRIPortNo); // If you want to create a socket for listening to wPortNumber ((Source Sorvar = Socket (AFNAT, SOCAKRR, 0)) == INVALID_SOCKET) {return incorrect; } // to bind the socket with wPortNumber if (bind (sourceworwer, (sokadar *) and server server, size (server server)) = 0) {return incorrect; } // to listen for connections on wPortNumber (Listen (sockers, somexone)! = 0) wrong (return); } // Getting the IP address of sockaddr_in insock unit that connects the structure; Int Inslane = Psychophag (Unsecured); // to accept connection to wPortNumber pLantronics-> M_Socket = Accept (Sourceworwer, (Structured Socadar *) and Inacoc, and Inkclen); If (PLentronics-> gt; m_Socket == INVALID_SOCKET) {closed (source server, 2); Port (source server); return false; } // DWORD dwNonBlocking = 1 for non-blocking socket; If (ioctlsocket (pLantronics-> m_Socket, FIONBIO, & dwNonBlocking)) {closed (pLantronics-> m_Socket, 2); Closesocket (pLantronics-> m_Socket); return false; } PLantronics-> m_sModemName = inet_ntoa (insock.sin_addr);  

Now I

  m_Socket ++; // Changing to any other number is ideally hoping that send recv to fail to send.  

Still sending sqkET_ERROR returns the recv socket functions without success. I hope it has to throw an error.

Am I doing something wrong?

This is due to the strange nature of Windows - when created, they are divisible by four and When their two lowest bits are used they are ignored. Before enlarging a handle, m_Socket look the same socket as before (only when you increase it by four, the function will return an error - unless the value is handled by another) .

In this way you should not check the open handle, while there are other ways to calculate open handles, you should not use them. Do not depend on the system to keep track of your handles - track them yourself.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -