While following a tutorial on how to create a simple chat server I stumbled upon this problem: <br>
AttributeError: ChatServer instance has no attribute 'decriptors'<br>
<br>
here is my code:<br>
#...................................................................................<br>
import socket<br>
import select<br>
<br>
class ChatServer:<br>
<br>
def __init__(self,port):<br>
self.port = port;<br>
<br>
self.srvsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br>
self.srvsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)<br>
self.srvsock.bind(("", port))<br>
self.srvsock.listen(5)<br>
<br>
self.descriptors = [self.srvsock]<br>
print 'Chat Server started on port %s' % port<br>
<br>
def run ( self ):<br>
<br>
while 1:<br>
<br>
#Await even on a readable socket descriptor<br>
(sread, swrite, sexc) = select.select(self.descriptors, [], [])<br>
<br>
#Iterate through the tagged read descriptors<br>
for sock in sread:<br>
<br>
#check if received a connect to the server<br>
if sock == self.srvsock:<br>
self.accept_new_connection()<br>
else:<br>
<br>
# received something on a client socket<br>
str = sock.recv(100)<br>
<br>
# check and see if the peer closed socket<br>
if str == '':<br>
host,port = sock.getpeername()<br>
str = 'Client left %s:%s\r\n' % (host, port)<br>
self.broadcast_string(str,sock)<br>
sock.close<br>
self.descriptors.remose(sock)<br>
else:<br>
host,port = sock.getpeername()<br>
newstr = '[%s:%s] %s' % (host, port, str)<br>
self.broadcast_string(newstr,sock)<br>
<br>
def broadcast_string(self, str, omit_sock):<br>
<br>
for sock in self.decriptors:<br>
if sock != self.srvsock and sock != omit_sock:<br>
sock.send(str)<br>
<br>
print str,<br>
<br>
<br>
def accept_new_connection( self ):<br>
<br>
newsock, (remhost, remport) = self.srvsock.accept()<br>
self.descriptors.append( newsock )<br>
<br>
newsock.send("You're connected to Chat Server!\r\n")<br>
str = "Client joined %s:%s\r\n" % (remhost, remport)<br>
self.broadcast_string( str, newsock )<br>
<br>
myserver = ChatServer( 23000 )<br>
myserver.run()<br>
#.......................................................................<br>
<br>
It starts fine but when someone connects, I get the error.<br>
[saiph]$ python telnetserver2.py<br>
Chat Server started on port 23000<br>
Traceback (most recent call last):<br>
File "telnetserver2.py", line 74, in ?<br>
myserver.run()<br>
File "telnetserver2.py", line 32, in run<br>
self.accept_new_connection()<br>
File "telnetserver2.py", line 69, in accept_new_connection<br>
self.broadcast_string( str, newsock )<br>
File "telnetserver2.py", line 53, in broadcast_string<br>
for sock in self.decriptors:<br>
AttributeError: ChatServer instance has no attribute 'decriptors'<br>
<br>
Any help would be appreciated! TIA<br>