<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 16, 2013, at 1:09 PM, Adam Heller &lt;<a href="mailto:sk82712@gmail.com">sk82712@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Guys,<div style="">I'll try to be as exact as I can be with my question, but it may end up being pretty broad. (I'm also relatively new to python, please go easy on my code although suggestions are of course welcome.)</div></div></blockquote><div><br></div><div>The main suggestion is "you can't parse TCP like this" :). &nbsp;You'll have this problem: &lt;<a href="http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#Whyisprotocol.dataReceivedcalledwithonlypartofthedataIcalledtransport.writewith">http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#Whyisprotocol.dataReceivedcalledwithonlypartofthedataIcalledtransport.writewith</a>&gt;</div><br><blockquote type="cite"><div dir="ltr"><div style="">The issue I'm running into:</div><div style="">When a user connects to the TCP server, they are displayed a welcome menu of things they can do. I'm simply catching the 'data' in an if statement to determine which menu item was picked. &nbsp;The problem is that some of the menu items require further input. &nbsp;I've had to use a series of bools to determine if a certain menu option was previously picked that will then directly send the data into the function / class. &nbsp;Is there an easier way to go about this? My current method seems a bit backwards and over complicated. &nbsp;I'm thinking I missed something in the documentation.</div></div></blockquote><div><br></div><blockquote type="cite"><div dir="ltr"><div style="">Anyway, here's the code:&nbsp;<a href="https://infotomb.com/q4293">https://infotomb.com/q4293</a>&nbsp;// Pass: twisted</div></div></blockquote><div><br></div><div>You should really attach the code itself to the email, so that future readers of the archive have some idea what you're talking about. &nbsp;Pastebins in general are not great, since the code will expire before your archived message does, and pastebins with passwords (!?) are even worse.</div><br><blockquote type="cite"><div dir="ltr"><div style="">(it was part of a challenge, so to speak, don't take too much out of context)</div>
<div style=""><br></div><div style="">You can see I had trouble with next() and dh(). &nbsp;I'm now trying to move this TCP 'framework' over to another project (the above was already submitted), and I'm still running into the same issues.</div></div></blockquote><br></div><div>You should try separating out your concerns a bit. &nbsp;The protocol should just parse the bytes into something meaningful, then call methods on some other, higher-level object that isn't just manipulating strings.</div><div><br></div><div>The "other, higher-level object" in your case might be a state machine of some kind, or you might just have an object representing the mode that you're currently in and switch that out for different modes.</div><div><br></div><div>This isn't an issue with Twisted though; Twisted just calls some methods on your objects in order to tell you what happened; what happens next is up to you. &nbsp;So it's a general program architecture issue.</div><div><br></div><div>This is very general advice, obviously, because I'm not sure what you are specifically asking, nor what your program is really intended to do. &nbsp;What kind of client is talking to this system? &nbsp;Did you invent the protocol yourself, or did it come from somewhere else? &nbsp;What is 'dh()' even trying to accomplish? &nbsp;Etc, etc.</div><div><br></div><div><br></div><div>-glyph</div></body></html>