Python Multithreading returns Bad File Descriptor? -
so, making chat server (how original!), , using multithreading
handle data sending/recieving, alongside logging , (soon be) server-sided commands. anyhoo.. run server, far. run client, hey! works! relaunch client , ;
exception in thread thread-5: traceback (most recent call last): file "c:\python27\lib\threading.py", line 810, in __bootstrap_inner self.run() file "c:\users\kuro\desktop\pychat\server.py", line 51, in run s.listen(9999) file "c:\python27\lib\socket.py", line 224, in meth return getattr(self._sock,name)(*args) file "c:\python27\lib\socket.py", line 170, in _dummy raise error(ebadf, 'bad file descriptor') error: [errno 9] bad file descriptor
on server, still works. no errors on client, yet. run client again, , happens; [errno 10061] no connection made because target machine actively refused it
. no server in/output. here's server code:
import socket import threading import sys import os import time s = socket.socket(socket.af_inet, socket.sock_stream) ip = raw_input("ip host server on: ") port = 9340 dat = none s.bind((ip,port)) class recvdat(threading.thread): def __init__(self, tid, tn): threading.thread.__init__(self) self.tid = tid self.tn = tn def run(self): global dat, conn while true: try: dat = conn.recv(1048) except: dat = none s.close() break if dat == "/exit" or none: s.close() break else: print dat chtlg.write(dat) dat = none class senddat(threading.thread): def __init__(self, tid, tn): threading.thread.__init__(self) self.tid = tid self.tn = tn def run(self): pass class acconn(threading.thread): def __init__(self, tid, tn): threading.thread.__init__(self) self.tid = tid self.tn = tn def run(self): global conn, act, actid s.listen(9999) conn, addr = s.accept() rdt = recvdat(2,"rdt") actid = actid+1 act = acconn(actid,"act") act.start() rdt.start() #print "client connected ip "+addr cwd = os.getcwd() chtlg = open(cwd+"/chatlog",'a') actid = 0 act = acconn(actid,"act") act.start() while true: time.sleep(2.5) pass
yes, very bad excuse of multithreading program, however, incomplete because buried in making client, , don't use classes or multithreading
often..
any @ appreciated!
Comments
Post a Comment