Bad File Descriptor Socket Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might
Socket Bad File Descriptor Python
have Meta Discuss the workings and policies of this site About raise error ebadf bad file descriptor Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting errno 9 bad file descriptor python ads with 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
Errno 9 Socket
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python socket (Socket Error Bad File Descriptor) up vote 9 down vote favorite The following receiveFile() function reads a filename and file data from the socket and splits it using the delimiter $. But I am unable to close
Connect:errno=9
the socket and a Bad file descriptor error is raised. If I comment out the self.server_socket.close() statement then there is no error but the socket is listening forever. Code:- def listen(self): self.server_socket.listen(10) while True: client_socket, address = self.server_socket.accept() print 'connected to', address self.receiveFile(client_socket) def receiveFile(self,sock): data = sock.recv(1024) data = data.split("$"); print 'filename', data[0] f = open(data[0], "wb") #data = sock.recv(1024) print 'the data is', data[1] f.write(data[1]) data = sock.recv(1024) while (data): f.write(data) data=sock.recv(1024) f.close() self.server_socket.close() print 'the data is', data print "File Downloaded" Traceback:- Traceback (most recent call last): File "server.py", line 45, in
here for a quick overview of the site Help Center Detailed answers to any questions you might python bad file descriptor have Meta Discuss the workings and policies of this site About
Python Socket Close
Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads ioerror: [errno 9] bad file descriptor with 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, http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor just like you, helping each other. Join them; it only takes a minute: Sign up 'socket.error: [Errno 9] Bad file descriptor' as I run my client up vote 0 down vote favorite as I run my client, my server collapse, it says: Traceback (most recent call last): File "C:/Users/Or/PycharmProjects/2.6/cyber.py", line 17, in
here for a quick overview of the site Help Center http://stackoverflow.com/questions/28495956/python-socket-programming-bad-file-descriptor-error Detailed answers to any questions you might have Meta Discuss http://stackoverflow.com/questions/11258781/bad-file-descriptor-with-linux-socket-write-bad-file-descriptor-c the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x bad file 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 Python Socket Programming - Bad file descriptor error up vote 1 down vote favorite I'm trying to create a bad file descriptor simple server, and keep getting the following error in IDLE: File "C:\Python27\lib\socket.py", line 202, in accept sock, addr = self._sock.accept() File "C:\Python27\lib\socket.py", line 170, in _dummy raise error(EBADF, 'Bad file descriptor') error: [Errno 9] Bad file descriptor This is my code. I've tried understanding why, and it has something to do with closing one of the sockets and then trying to use it again but I don't really get how I'm supposed to fix it. Any and all help is appreciated. :) from socket import * serverSocket = socket(AF_INET, SOCK_STREAM) port=10101 serverSocket.bind(('',port)) serverSocket.listen(5) while True: print 'Ready to serve...' connectionSocket, addr = serverSocket.accept() try: message = serverSocket.recv(1024) filename = message.split()[1] f = open(filename[1:]) outputdata = f.read() connectionSocket.send("HTTP/1.1 200 OK\r\n\n") for i in range(0, len(outputdata)): connectionSocket.send(outputdata[i]) connectionSocket.close() except IOError: connectionSocket.send('HTTP/1.1 404 File not found\r\n\n') connectionSocket.close() serverSocket.close() serverSocket.close() python sockets tcp share|improve this question aske
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 Overflow the company Business Learn more about hiring 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 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 with Linux Socket write() Bad File Descriptor C up vote -1 down vote favorite I have an interesting problem with write(2) function. PrepareResponseForSetCoordinates function causes bad file descriptor error on write. Here is the line of error: perror("ERROR writing to socket"); total output: ERROR writing to socket: Bad file descriptor I am sure that I have established the connection because PrepareResponseForConnectionTest works like a charm. Can you have any idea about the reason of the error? When I use gcc as compiler there was no problem. After that because of using multiple new cpp sources I am using g++ as compiler and I have this error. Regards Here below my code: #define MAX_PMS_MESSAGE_LEN (4096) unsigned char baCommBuffer[MAX_PMS_MESSAGE_LEN]; unsigned char PrepareResponseForSetCoordinates(void) { unsigned char baTempBuff[255]={0}; unsigned short bCnt=0,i=0,bCsum=0,bCnt2=0; time_t lEpochTime; time_t lSessionTime; memset(baTempBuff,0,sizeof(baTempBuff)); memset(baCommBuffer,0,sizeof(baCommBuffer)); bzero(baCommBuffer,MAX_PMS_MESSAGE_LEN); bzero(baTempBuff,sizeof(baTempBuff)); lEpochTime = time(NULL); baCommBuffer[bCnt++] = START_CHAR; baCommBuffer[bCnt++] = START_CHAR; baCommBuffer[bCnt++] = PACKET_SEPERATOR; sprintf((char*)baTempBuff,"%ld",(un