Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60324 > unrolled thread

stuck at this from so much time,need help....please ..

Started byBhanu Karthik <bhanukarthik2002@gmail.com>
First post2013-11-23 14:15 -0800
Last post2013-11-24 09:41 +1100
Articles 10 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  stuck at this from so much time,need help....please .. Bhanu Karthik <bhanukarthik2002@gmail.com> - 2013-11-23 14:15 -0800
    Re: stuck at this from so much time,need help....please .. Chris Angelico <rosuav@gmail.com> - 2013-11-24 09:23 +1100
      Re: stuck at this from so much time,need help....please .. Bhanu Karthik <bhanukarthik2002@gmail.com> - 2013-11-23 14:29 -0800
        Re: stuck at this from so much time,need help....please .. Chris Angelico <rosuav@gmail.com> - 2013-11-24 09:32 +1100
        Re: stuck at this from so much time,need help....please .. MRAB <python@mrabarnett.plus.com> - 2013-11-23 22:58 +0000
      Re: stuck at this from so much time,need help....please .. Bhanu Karthik <bhanukarthik2002@gmail.com> - 2013-11-23 14:33 -0800
        Re: stuck at this from so much time,need help....please .. Roy Smith <roy@panix.com> - 2013-11-23 17:37 -0500
          Re: stuck at this from so much time,need help....please .. Bhanu Karthik <bhanukarthik2002@gmail.com> - 2013-11-23 14:39 -0800
            Re: stuck at this from so much time,need help....please .. Chris Angelico <rosuav@gmail.com> - 2013-11-24 09:46 +1100
        Re: stuck at this from so much time,need help....please .. Chris Angelico <rosuav@gmail.com> - 2013-11-24 09:41 +1100

#60324 — stuck at this from so much time,need help....please ..

FromBhanu Karthik <bhanukarthik2002@gmail.com>
Date2013-11-23 14:15 -0800
Subjectstuck at this from so much time,need help....please ..
Message-ID<a4a25260-4786-4b2b-81f5-5da87b05d301@googlegroups.com>
data = sock.recv(RECV_BUFFER)
			    username = str(sock.getpeername())
			    username = usernames[username]	
			    if command == "/quit":
				print data
				sock.send("bye")			
				sock.close()
	                	CONNECTION_LIST.remove(sock)

even if the received data is '/quit' the if condition not excuting...please help.

[toc] | [next] | [standalone]


#60325

FromChris Angelico <rosuav@gmail.com>
Date2013-11-24 09:23 +1100
Message-ID<mailman.3102.1385245397.18130.python-list@python.org>
In reply to#60324
On Sun, Nov 24, 2013 at 9:15 AM, Bhanu Karthik
<bhanukarthik2002@gmail.com> wrote:
> data = sock.recv(RECV_BUFFER)
>                             username = str(sock.getpeername())
>                             username = usernames[username]
>                             if command == "/quit":
>                                 print data
>                                 sock.send("bye")
>                                 sock.close()
>                                 CONNECTION_LIST.remove(sock)
>
> even if the received data is '/quit' the if condition not excuting...please help.

At what point is command set? You're setting data here; is command
supposed to be derived from data?

This looks like a MUD or IRC style of server, which would suggest that
commands are terminated by end-of-line. You may need to take content
from the socket (currently in data) and split it off on either "\r\n"
or "\n". But it's hard to tell from this small snippet.

ChrisA

[toc] | [prev] | [next] | [standalone]


#60326

FromBhanu Karthik <bhanukarthik2002@gmail.com>
Date2013-11-23 14:29 -0800
Message-ID<8b9e38b9-4793-4cde-ae77-99c31380c4d1@googlegroups.com>
In reply to#60325
On Saturday, 23 November 2013 14:23:08 UTC-8, Chris Angelico  wrote:
> On Sun, Nov 24, 2013 at 9:15 AM, Bhanu Karthik
> 
> <bhanukarthik2002@gmail.com> wrote:
> 
> > data = sock.recv(RECV_BUFFER)
> 
> >                             username = str(sock.getpeername())
> 
> >                             username = usernames[username]
> 
> >                             if command == "/quit":
> 
> >                                 print data
> 
> >                                 sock.send("bye")
> 
> >                                 sock.close()
> 
> >                                 CONNECTION_LIST.remove(sock)
> 
> >
> 
> > even if the received data is '/quit' the if condition not excuting...please help.
> 
> 
> 
> At what point is command set? You're setting data here; is command
> 
> supposed to be derived from data?
> 
> 
> 
> This looks like a MUD or IRC style of server, which would suggest that
> 
> commands are terminated by end-of-line. You may need to take content
> 
> from the socket (currently in data) and split it off on either "\r\n"
> 
> or "\n". But it's hard to tell from this small snippet.
> 
> 
> 
> ChrisA

sorry its not command its data....

I miss wrote it here...

[toc] | [prev] | [next] | [standalone]


#60327

FromChris Angelico <rosuav@gmail.com>
Date2013-11-24 09:32 +1100
Message-ID<mailman.3103.1385245963.18130.python-list@python.org>
In reply to#60326
On Sun, Nov 24, 2013 at 9:29 AM, Bhanu Karthik
<bhanukarthik2002@gmail.com> wrote:
> sorry its not command its data....
>
> I miss wrote it here...

Okay. Start by copying and pasting your actual code, and saying what
you're doing to trigger it. If this is a stream socket (eg TCP), you
have no way of knowing where one read will end and the next start, so
you'll need to do some kind of buffering and splitting.

Also, please use something better than Google Groups; your posts are
looking rather ugly, and it's the fault of your client rather than
yourself.

ChrisA

[toc] | [prev] | [next] | [standalone]


#60333

FromMRAB <python@mrabarnett.plus.com>
Date2013-11-23 22:58 +0000
Message-ID<mailman.3107.1385247503.18130.python-list@python.org>
In reply to#60326
On 23/11/2013 22:29, Bhanu Karthik wrote:> On Saturday, 23 November 2013 
14:23:08 UTC-8, Chris Angelico  wrote:
 >> On Sun, Nov 24, 2013 at 9:15 AM, Bhanu Karthik
 >> <bhanukarthik2002@gmail.com> wrote:
 >> > data = sock.recv(RECV_BUFFER)
 >> >                             username = str(sock.getpeername())
 >> >                             username = usernames[username]
 >> >                             if command == "/quit":
 >> >                                 print data
 >> >                                 sock.send("bye")
 >> >                                 sock.close()
 >> >                                 CONNECTION_LIST.remove(sock)
 >> >
 >> > even if the received data is '/quit' the if condition not 
excuting...please help.
 >>
 >> At what point is command set? You're setting data here; is command
 >> supposed to be derived from data?
 >>
 >> This looks like a MUD or IRC style of server, which would suggest that
 >> commands are terminated by end-of-line. You may need to take content
 >> from the socket (currently in data) and split it off on either "\r\n"
 >> or "\n". But it's hard to tell from this small snippet.
 >>
 >> ChrisA
 >
 > sorry its not command its data....
 >
 > I miss wrote it here...
 >
If the 'if' condition not executing then it must be because the
received data isn't "/quit", so what is it? Print it out, or, even
better, print out repr(data), which will show you any spaces or "\n" in
it.

sock.recv(RECV_BUFFER) will receive up to RECV_BUFFER bytes, so if the
sender is sending other stuff after the "/quit" and RECV_BUFFER > 5,
then you might be receiving some of that later stuff too.

[toc] | [prev] | [next] | [standalone]


#60328

FromBhanu Karthik <bhanukarthik2002@gmail.com>
Date2013-11-23 14:33 -0800
Message-ID<8445e47e-7efe-4f37-9b40-db2896d581f8@googlegroups.com>
In reply to#60325
On Saturday, 23 November 2013 14:23:08 UTC-8, Chris Angelico  wrote:
> On Sun, Nov 24, 2013 at 9:15 AM, Bhanu Karthik
> 
> <bhanukarthik2002@gmail.com> wrote:
> 
> > data = sock.recv(RECV_BUFFER)
> 
> >                             username = str(sock.getpeername())
> 
> >                             username = usernames[username]
> 
> >                             if command == "/quit":
> 
> >                                 print data
> 
> >                                 sock.send("bye")
> 
> >                                 sock.close()
> 
> >                                 CONNECTION_LIST.remove(sock)
> 
> >
> 
> > even if the received data is '/quit' the if condition not excuting...please help.
> 
> 
> 
> At what point is command set? You're setting data here; is command
> 
> supposed to be derived from data?
> 
> 
> 
> This looks like a MUD or IRC style of server, which would suggest that
> 
> commands are terminated by end-of-line. You may need to take content
> 
> from the socket (currently in data) and split it off on either "\r\n"
> 
> or "\n". But it's hard to tell from this small snippet.
> 
> 
> 
> ChrisA

 data = sock.recv(RECV_BUFFER)
			    username = str(sock.getpeername())
			    username = usernames[username]	
			    if data == "/quit":
				print data
				sock.send("bye")			
				sock.close()
	                	CONNECTION_LIST.remove(sock)


this is exact code..
it is not even entering the if ...
I tried ( c= (data is '/quit')if c)

when i print c ,its printing false....I dont understand what is happening...please help..

[toc] | [prev] | [next] | [standalone]


#60329

FromRoy Smith <roy@panix.com>
Date2013-11-23 17:37 -0500
Message-ID<roy-E94E09.17370923112013@news.panix.com>
In reply to#60328
In article <8445e47e-7efe-4f37-9b40-db2896d581f8@googlegroups.com>,
 Bhanu Karthik <bhanukarthik2002@gmail.com> wrote:

>  data = sock.recv(RECV_BUFFER)
> 			    username = str(sock.getpeername())
> 			    username = usernames[username]	
> 			    if data == "/quit":
> 				print data
> 				sock.send("bye")			
> 				sock.close()
> 	                	CONNECTION_LIST.remove(sock)
> 
> 
> this is exact code..
> it is not even entering the if ...
> I tried ( c= (data is '/quit')if c)

That can't be the exact code.  What you posted is a syntax error because 
the line after the "if" statement isn't indented properly.

[toc] | [prev] | [next] | [standalone]


#60330

FromBhanu Karthik <bhanukarthik2002@gmail.com>
Date2013-11-23 14:39 -0800
Message-ID<b3becfe3-09ea-4bd9-a3b4-3c1ef6293dcf@googlegroups.com>
In reply to#60329
On Saturday, 23 November 2013 14:37:09 UTC-8, Roy Smith  wrote:
> In article <8445e47e-7efe-4f37-9b40-db2896d581f8@googlegroups.com>,
> 
>  Bhanu Karthik <bhanukarthik2002@gmail.com> wrote:
> 
> 
> 
> >  data = sock.recv(RECV_BUFFER)
> 
> > 			    username = str(sock.getpeername())
> 
> > 			    username = usernames[username]	
> 
> > 			    if data == "/quit":
> 
> > 				print data
> 
> > 				sock.send("bye")			
> 
> > 				sock.close()
> 
> > 	                	CONNECTION_LIST.remove(sock)
> 
> > 
> 
> > 
> 
> > this is exact code..
> 
> > it is not even entering the if ...
> 
> > I tried ( c= (data is '/quit')if c)
> 
> 
> 
> That can't be the exact code.  What you posted is a syntax error because 
> 
> the line after the "if" statement isn't indented properly.

indentation is correct when I trying to paste it here,it is showing like it is unindented.

[toc] | [prev] | [next] | [standalone]


#60332

FromChris Angelico <rosuav@gmail.com>
Date2013-11-24 09:46 +1100
Message-ID<mailman.3105.1385246805.18130.python-list@python.org>
In reply to#60330
On Sun, Nov 24, 2013 at 9:39 AM, Bhanu Karthik
<bhanukarthik2002@gmail.com> wrote:
> indentation is correct when I trying to paste it here,it is showing like it is unindented.

That's because Google Groups mucks things up. Get a better client.

ChrisA

[toc] | [prev] | [next] | [standalone]


#60331

FromChris Angelico <rosuav@gmail.com>
Date2013-11-24 09:41 +1100
Message-ID<mailman.3104.1385246500.18130.python-list@python.org>
In reply to#60328
On Sun, Nov 24, 2013 at 9:33 AM, Bhanu Karthik
<bhanukarthik2002@gmail.com> wrote:
> this is exact code..
> it is not even entering the if ...
> I tried ( c= (data is '/quit')if c)
>
> when i print c ,its printing false....I dont understand what is happening...please help..

Again, please get off Google Groups. Have a look at how your posts come out:

https://mail.python.org/pipermail/python-list/2013-November/661005.html

Note how your quoted text is double-spaced. This is one of the most
obvious and obnoxious problems, though not the only one.

You have two problems here. Firstly, comparing strings with 'is' is
wrong in most cases[1], so stick with ==. And secondly, my crystal
ball says that you're typing "/quit" and pressing enter, so your
socket read will be "/quit\r\n" or "/quit\n". To properly handle this,
you'll need to buffer and split as I was describing.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web