<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Miguel.<br>
<br>
En Python 3.2 el método recv() del objeto socket devuelve un objeto
"bytes" (<a class="moz-txt-link-freetext"
href="http://docs.python.org/py3k/library/socket.html#socket.socket.recv">http://docs.python.org/py3k/library/socket.html#socket.socket.recv</a>).
Ya no devuelve un objeto "str". Así que, como decimos en Chile,
estas comparando "peras con manzanas".<br>
<br>
Para Python 3.2 sería correcto esto:<br>
<br>
<font face="Arial">if recibido == b"quit": <br>
</font><br>
Pero esta línea no funcionaría en Python 2.5 ya que no existe el
objeto bytes. <br>
Si quieres hacer tu código 2.x y 3.x tendrás que hacer ajustes.<br>
<br>
Saludos.<br>
<br>
On 26/09/2011 12:39 PM, Miguel Barraza wrote:
<blockquote cite="mid:9BAFF1E8A7D04ABAA888A1C83DF783CD@AYUMI"
type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<style>.hmmessage P {
        PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
BODY.hmmessage {
        FONT-FAMILY: Tahoma; FONT-SIZE: 10pt
}
</style>
<meta name="GENERATOR" content="MSHTML 8.00.6001.18702">
<div><font face="Arial">hola, aqui probando y probando llegué a
una duda muy estraña.</font></div>
<div><font face="Arial">este código de servidor de sockets lo
probé con python 2.5 portable y funciona correctamente, lo
probé en otra pc con python 2.4 y tube el mismo resultado,
pero en mi pc con python 3.2 no funciona, se cierra
automaticamente el interprete y no se porque no me lo quiere
correr, la sintacsis cambia para python 3.2?. o porque podría
ocurrir este problema.</font></div>
<div> </div>
<div><font face="Arial">aclaro: utilizo windows xp con python 3.2
instalado, y para pruebas tengo el python 2.5 portable.</font></div>
<div> </div>
<div><font face="Arial">código del ejemplo:</font></div>
<div> </div>
<div><font face="Arial">import socket <br>
<br>
s = socket.socket() <br>
s.bind(("localhost", 9999)) <br>
s.listen(1) <br>
<br>
sc, addr = s.accept() <br>
<br>
while True: <br>
recibido = sc.recv(1024) <br>
if recibido == "quit": <br>
break <br>
print "Recibido:", recibido <br>
sc.send(recibido) <br>
<br>
print "adios" <br>
<br>
sc.close() <br>
s.close() </font></div>
<div> </div>
<div><font face="Arial">fin del código.</font></div>
<div> </div>
<div><font face="Arial">gracias, saludos.</font></div>
<div> </div>
<div><font face="Arial">atte, Miguel</font></div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Python-es mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-es@python.org">Python-es@python.org</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/python-es">http://mail.python.org/mailman/listinfo/python-es</a>
FAQ: <a class="moz-txt-link-freetext" href="http://python-es-faq.wikidot.com/">http://python-es-faq.wikidot.com/</a>
</pre>
</blockquote>
</body>
</html>