Hey,<div><br></div><div>I'm also using txwebsocket for this project. See <a href="https://github.com/phrearch/hwios">https://github.com/phrearch/hwios</a></div><div><br></div><div>kind regards,</div><div><br></div><div>
Jeroen<br><br><div class="gmail_quote">2011/9/6 João Ricardo Mattos e Silva <span dir="ltr"><<a href="mailto:joaoricardo000@gmail.com">joaoricardo000@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hey,<div>my first e-mail on this list, I`m beginning to code with twisted, started after a research about building c10k servers.. (with python)</div><div>I am using this lib, heard it is the best for working with websockets (correct me if you know another)</div>
<div><a href="https://github.com/wulczer/txWebSocket" target="_blank">https://github.com/wulczer/txWebSocket</a></div><div><br></div><div>Well,</div><div>There is what I want to do:</div><div>I have:</div><div><br></div>
<div><div> site = WebSocketSite(root)</div>
<div> site.addChatHandler('/room<b>1</b>', Chathandler)</div><div> reactor.listenTCP(8080, site) </div><div><br></div><div>where</div><div> </div><div>class Chathandler(WebSocketHandler):</div><div> users = set()</div>
<div> def __init__(self, transport):</div><div> WebSocketHandler.__init__(self, transport)</div><div><br></div><div> def __del__(self):</div><div> print 'Deleting handler'</div><div> </div>
<div> def setUsers(self,usr):</div><div> self.users = usr</div><div><br></div><div> def frameReceived(self, frame):</div><div> adr = self.transport.getPeer()</div><div> print "Msg rcv from: ", adr</div>
<div> self.sendChat(adr,frame)</div><div><br></div><div> def connectionMade(self):</div><div> print 'Connected to client.'</div><div> self.users.add(self)</div><div><br></div><div> def connectionLost(self, reason):</div>
<div> print 'Lost connection.'</div><div> if self in self.users:</div><div> self.users.remove(self)</div><div> </div><div> def sendChat(self,fr,msg):</div><div> for u in self.users:</div>
<div> u.transport.write(str(fr)+msg)</div><div><br></div><div>My problem is:</div><div>If I do this:</div><div><div> site = WebSocketSite(root)</div><div> site.addChatHandler('/room<b>1</b>', Chathandler)</div>
<div><div> site.addChatHandler('/room<b>2</b>', Chathandler)</div></div><div> site.addChatHandler('/room<b>3</b>', Chathandler)</div><div> reactor.listenTCP(8080, site) </div></div><div><br></div>
<div><div>will not work (every room will comunicate with every room), because the users = set() will be globally between the handlers..</div></div><div>If I put on the __init__, every call on /roomX will have your personal set() of users including only themselfs.</div>
<div><br></div><div>I am kind stuck on this, I`m new to websocket and server programming, so I don`t even know if is the best way to code a chatroom server. </div><div>If you read this far ans have any (even it looks that stupid for you), might help right now (:</div>
<div><br></div><div>Thanks,</div><div><br></div><font color="#888888">-- <br><b>João Ricardo Mattos e Silva</b><br><br><span style="font-size:x-small">Graduando em Ciência da Computação na Universidade Federal de Santa Catarina<br>
</span><br>
<b><font face="'courier new', monospace">Cel: </font></b><font face="'courier new', monospace"><a href="tel:%2B55%20%2848%29%2096190063" value="+554896190063" target="_blank">+55 (48) 96190063</a> | <b>Skype:</b> jricardomsilva | <b> Msn: </b><a href="mailto:joaoricardo@globalite.com.br" target="_blank">joaoricardo@globalite.com.br</a></font><br>
</font></div>
<br>_______________________________________________<br>
Twisted-web mailing list<br>
<a href="mailto:Twisted-web@twistedmatrix.com">Twisted-web@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web</a><br>
<br></blockquote></div><br></div>