Raise Error Ebadf 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 Overflow the company Business errno 9 bad file descriptor socket Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Raise Error Ebadf Bad File Descriptor Python
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like errno 9 bad file descriptor python 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
Socket Bad File Descriptor Python
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 = python bad file descriptor 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
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Python Socket Close
and policies of this site About Us Learn more about Stack Overflow
Ioerror: [errno 9] Bad File Descriptor
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags python socket select 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 http://stackoverflow.com/questions/4642345/python-client-server-question takes a minute: Sign up Python Socket Programming - Bad file descriptor error up vote 1 down vote favorite I'm trying to create 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 http://stackoverflow.com/questions/28495956/python-socket-programming-bad-file-descriptor-error 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 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.
Sign in Pricing Blog Support Search GitHub This repository Watch 77 Star 331 Fork 315 noxrepo/pox https://github.com/noxrepo/pox/issues/28 Code Issues 20 Pull requests 12 Projects 0 Wiki Pulse Graphs New issue Bad file descriptor in io_worker #28 Closed MurphyMc opened this Issue Jun 23, 2012 https://groups.google.com/d/topic/wxpython-users/OEE_3bdRTS8 · 2 comments Labels NotABug Milestone No milestone Assignees No one assigned 2 participants Collaborator MurphyMc commented Jun 23, 2012 Here's a stack bad file trace from Sam: File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner │ self.run() │ File "/usr/lib/python2.7/threading.py", line 505, in run │ self.__target(*self.__args, **self.__kwargs) │ File "/home/sam/code/debugger/sts/../pox/pox/lib/recoco/recoco.py", line 574, in _threadProc │ xl.keys(), timeout ) │ File "/home/sam/code/debugger/sts/../pox/pox/lib/ioworker/io_worker.py", line 77, in fileno │ return self.socket.fileno() │ File "/usr/lib/python2.7/socket.py", line 224, in meth │ return getattr(self._sock,name)(*args) bad file descriptor │ File "/usr/lib/python2.7/socket.py", line 170, in _dummy │ raise error(EBADF, 'Bad file descriptor') │ error: [Errno 9] Bad file descriptor Collaborator MurphyMc commented Jun 23, 2012 The problem would seem to be that close() is being called on a worker socket while Select() either still has the socket (because close() is called from other thread or maybe another Task, for example), or close() is called on a socket that is passed back into Select(). It's not immediately clear to me how the latter could be happening, because _workers.remove() or _workers.discard() seems to be called in every place that close() is called on a worker socket. The former is a possibility, though I don't know the io_worker code well enough to immediately say. 96b8074 fixed a similar problem by changing calls from socket.close() to socket.shutdown(), relying on recoco to close them eventually. This might work here? Collaborator samwhitlock commented Jun 23, 2012 I was accidentally closing m
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen