Error Recvfrom Bad File Descriptor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Bad File Descriptor Error In C
Overflow the company Business Learn more about hiring developers or posting ads with us Stack write error bad file descriptor Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community error 9 bad file descriptor of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why am I getting a bad file descriptor error? up vote 2 down vote favorite I am
Wget Error Bad File Descriptor
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. struct hostent * pHostInfo; struct sockaddr_in Address; long nHostAddress; char pBuffer[BUFFER_SIZE]; unsigned nReadAmount;
Sendto Bad File Descriptor
int nHostPort = atoi(port); vector
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about connect bad file descriptor Stack Overflow the company Business Learn more about hiring developers or posting ads with
Bad File Descriptor C
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bad File Descriptor - Simple UDP Client up vote 1 down vote favorite http://stackoverflow.com/questions/7406290/why-am-i-getting-a-bad-file-descriptor-error When attempting to create a simple UDP client, my code successfully opens the socket and reads in a small buffer from a file to be sent to a server specified by host address and port number by command line arguments. However, the sendto and recvfrom both fail with "Bad File Descriptor" and I can't figure out why. void main(int argc, char* argv[]){ int s, n=0, obytes, inbytes; struct sockaddr_in sin; http://stackoverflow.com/questions/4843930/bad-file-descriptor-simple-udp-client char *buffer; int address = 0; //Checks socket if((s = socket(AF_INET, SOCK_DGRAM, 0))<0) { printf("Error creating socket\n"); exit(0); } //Resets values in socket structure memset((char*)&sin, 0, sizeof(sin)); sin.sin_port = htons(atoi(argv[2])); sin.sin_family = AF_INET; sin.sin_addr.s_addr = inet_addr(argv[1]); printf("%d\n", sin.sin_addr.s_addr); /*Opens file to be sent and reads into buffer*/ FILE *readFile; readFile = fopen(argv[3], "r"); //Checks if file to be read can be opened if (readFile==NULL) { perror ("Error opening file"); } //Reads in all the characters to a buffer else{ while (!feof(readFile)) { buffer[n] = fgetc (readFile); n++; } buffer[n] = '\0'; printf ("Total number of bytes: %d\n", n); for(int i = 0; i< n; i++){ printf("%c", buffer[i]); } } printf("File was opened\n"); //Sends the buffer to the destination designated by the socket structure and checks to see if bytes were sent if((obytes = sendto(s, buffer, strlen(buffer), 0, (struct sockaddr *)&sin, sizeof(sin))) == -1 ) { perror("Sendto() error!"); exit(1); } printf("%d bytes were sent\n",obytes); //Receives response from the server and checks to see if bytes were actually received /* if((inbytes = recvfrom(s, buffer, strlen(buffer)+28, 0, (struct sockaddr *)&sin, sizeof(struct sockaddr*))) == -1 ) { perror("Recvfrom() error!"); exit(1); }*/ printf("%d bytes were received.\n", inbytes); //Closes file fclose (readFile); } c sockets networking udp udpclient share|improve this question edited Jan 30
here for a quick overview of the site Help Center Detailed answers to any http://stackoverflow.com/questions/30756210/unable-to-receive-data-after-connection-getting-bad-file-descriptor-error questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring http://www.linuxforums.org/forum/programming-scripting/156104-udp-server-not-sending-client.html developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is bad file a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Unable to receive data after connection getting Bad file Descriptor error up vote 1 down vote favorite I am working on a Multi-threaded Server application in C using Pthreads(Linux). My system bad file descriptor is dual boot.Windows 7 as well as Ubuntu. I restarted my PC and booted into Windows from Ubuntu, Before restarting my server application was working Fine.After i again booted to ubuntu from windows. and started my server i start getting following Error when a client connects. recv failed: Bad file descriptor Here is My code: Main.C #include
Today's Posts Advanced Search Find the answer to your Linux question: Entire Site Articles Downloads Forums Linux Hosting Forum GNU Linux Zone Programming / Scripting UDP server not sending to client If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be displayed. ** Linuxforums now supports the Tapatalk app for your mobile device. Page 1 of 2 1 2 Last Jump to page: Results 1 to 10 of 13 Thread: UDP server not sending to client Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Enjoy an ad free experience by logging in. Not a member yet? Register. 11-23-2009 #1 a_n_h View Profile View Forum Posts Private Message View Articles Just Joined! Join Date May 2009 Posts 35 UDP server not sending to client Hi there, I have a problem with my connected UDP server, I want to to send info to the client using send(), but for some reason I always get an error message such as: "bad file descriptor", any idea why? here is a sample of my code Code: while (1) { //recv worked fine if ((bytes = recv(serverSock, buffer, BUFFER_SIZE-1, 0)) < 1 ) { fprintf(stderr,"Failed to receive bytes from server\n"); } file = fopen(buffer, "r"); if( file == NULL ) { perror("stat"); memset(message,0xff,1); messageLength = strlen(message); //PROBLEM if ( send(clientSock,message,mesageLength, 0); != messageLength) { perror("stat"); exit(1); } } what I am trying to do, is that if for some reason I couldnt open the specified file, i should just send oxff to the client, but I am not able to do it, send() always returns -1 (error), any tips or idea why? thank u in advance Reply With Quote 11-23-2009 #2 Rubberman View Profile View Forum Posts Private Message View Articles Linux Guru Join Date Apr 2009 Location I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away. Posts 13,262 Please provide more code where you are creating and binding the sockets, as well as what the buffer size you are sending, etc. Sometimes, real fast is almost as good as real time. Just remember, Semper Gumbi - always be flexible! Reply With Quote 11-23-2009 #3 a_n_h View Profile View Forum Posts Private Message View Articles Just Joi