Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting a bad file descriptor error?
    text
    copied!<p>I am trying to write a short program that acts like a client, like telnet. I receive from the user input like so: www.google.com 80 (the port number) and /index.html However, I get some errors. When I write some debug information, it says that I have a bad file descriptor and Read Failed on file descriptor 100 messagesize = 0. </p> <pre><code>struct hostent * pHostInfo; struct sockaddr_in Address; long nHostAddress; char pBuffer[BUFFER_SIZE]; unsigned nReadAmount; int nHostPort = atoi(port); vector&lt;char *&gt; headerLines; char buffer[MAX_MSG_SZ]; char contentType[MAX_MSG_SZ]; int hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket == SOCKET_ERROR) { cout &lt;&lt; "\nCould Not Make a Socket!\n" &lt;&lt; endl; return 1; } pHostInfo = gethostbyname(strHostName); memcpy(&amp;nHostAddress,pHostInfo -&gt; h_addr, pHostInfo -&gt; h_length); Address.sin_addr.s_addr = nHostAddress; Address.sin_port=htons(nHostPort); Address.sin_family = AF_INET; if (connect(hSocket, (struct sockaddr *)&amp;Address, sizeof(Address)) == SOCKET_ERROR) { cout &lt;&lt; "Could not connect to the host!" &lt;&lt; endl; exit(1); } char get[] = "GET "; char http[] = " HTTP/1.0\r\nHost: "; char end[] = "\r\n\r\n"; strcat(get, URI); strcat(get, http); strcat(get, strHostName); strcat(get, end); strcpy(pBuffer, get); int len = strlen(pBuffer); send(hSocket, pBuffer, len, 0); nReadAmount = recv(hSocket,pBuffer, BUFFER_SIZE, 0); //Parsing of data here, then close socket if (close(hSocket) == SOCKET_ERROR) { cout &lt;&lt; "Could not close the socket!" &lt;&lt; endl; exit(1); } </code></pre> <p>Thanks! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload