Python Socket Error 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
Errno 9 Bad File Descriptor Python
about Stack Overflow the company Business Learn more about hiring developers or posting ads raise error(ebadf, 'bad file descriptor') with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Bad File Descriptor Error In C
Overflow is a community of 6.2 million 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 errno 9 socket 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 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 connect:errno=9 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 have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Socket Bad File Descriptor
the company Business Learn more about hiring developers or posting ads with us Stack python bad file descriptor Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Python Socket Close
6.2 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 http://stackoverflow.com/questions/16382899/python-socket-socket-error-bad-file-descriptor a 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 http://stackoverflow.com/questions/28495956/python-socket-programming-bad-file-descriptor-error 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 asked Feb 13 '15 at 9:08 Gustaf Svensson 15819 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote A couple of things: As user27994550 put in his code, you want to use message = connectionSocket.recv(1024) to receive messages, not the server socket. The other thing that both of your codes missed is you don't want to call serverSocket.close() in your except function unless you're closing the program overall. If you close the server socket, the next time you call connectionSocket, addr = serverSocket.accept() you won't be able to accept another connection. Hope this helps! share|improve this answer answered Feb 13 '15 at 22:16 Penguinfrank 24219 add a comment| up vote 0 down vote You are trying to use the "message" variable data without checking if its empty. I think this might be the problem. Try this: from socket i
here for a quick overview of the site Help Center Detailed answers to any questions you might http://stackoverflow.com/questions/38292142/python-socket-error-errno-9-bad-file-descriptor have Meta Discuss the workings and policies of this site About http://stackoverflow.com/questions/4642345/python-client-server-question 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 6.2 million programmers, bad file just like you, helping each other. Join them; it only takes a minute: Sign up python socket.error: [Errno 9] Bad file descriptor up vote 2 down vote favorite I wanted to make a server and a client with Python. It was supposed to make multiple connections, one, where the server is sending something to the bad file descriptor client, and one where the client is sending something to the server. The first connection worked fine, but the second one crashed with the message: socket.error: [Errno 9] Bad file descriptor Here is the Server: import socket import errno import pickle def Main(): host = '188.174.233.99' port = 66666 all_text = ['text1', 'text2', 'text3'] all_description = ['Test \n Description1\n', 'Test \n Description1\n', 'Test \n Description1\n'] all_images = ['unlock.png', 'unlock.png', 'unlock.png'] s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) s.bind((host, port)) s.listen(1) while True: c, addr = s.accept() c.setblocking(0) print "Connection from: " + str(addr) command = c.recv(1024) if command == 'GIVEALL': textstring = pickle.dumps([all_text, all_images, all_description])#verwandelt Liste in String c.send(textstring) else: try: new_event = pickle.loads(command) print new_event caption = new_event[0] image = new_event[1] describtion = new_event[2] city = new_event[3] except: pass try: c.close() s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) except socket.error as e: if e.errno != errno.ECONNRESET: raise pass if __name__ == '__main__': Main() And here is the Client: import socket import pickle from kivy.properties import StringProperty from kivy.properties import NumericProperty from ki
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 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python client / server question up vote 6 down vote favorite 2 I'm working on a bit of a project in python. I have a client and a server. The server listens for connections and once a connection is received it waits for input from the client. The idea is that the client can connect to the server and execute system commands such as ls and cat. This is my server code: import sys, os, socket host = '' port = 50105 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) print("Server started on port: ", port) s.listen(5) print("Server listening\n") conn, addr = s.accept() print 'New connection from ', addr while (1): rc = conn.recv(5) pipe = os.popen(rc) rl = pipe.readlines() file = conn.makefile('w', 0) file.writelines(rl[:-1]) file.close() conn.close() And this is my client code: import sys, socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' port = input('Port: ') s.connect((host, port)) cmd = raw_input('$ ') s.send(cmd) file = s.makefile('r', 0) sys.stdout.writelines(file.readlines()) When I start the server I get the right output, saying the server is listening. But when I connect with my client and type a command the server exits with this error: Traceback (most recent call last): File "server.py", line 21, in