[Python-es] UDPSock.recvfrom(buf) ??????? (buf) ???

Diego Uribe Gamez diego.uribe.gamez en gmail.com
Jue Jun 7 16:08:20 CEST 2012


Que determina el tamaño del paquete, si yo envió un dato de un computador a
otro que tanto se abre buff para recibir el tirón completo.

Sobre la información de la documentación solo encontré esto buffer
allocation on receive operations is automatic, and buffer length is
implicit on send operations. y el ejemplo con buffer para mi caso al final
del documento:

*# receive a packageprint s.recvfrom(65565)*

import socket
# the public network interfaceHOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interfaces =
socket.socket(socket.AF_INET, socket.SOCK_RAW,
socket.IPPROTO_IP)s.bind((HOST, 0))
# Include IP headerss.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packagess.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
*# receive a packageprint s.recvfrom(65565)*
# disabled promiscuous modes.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

Running an example several times with too small delay between executions,
could lead to this error:


socket.error: [Errno 98] Address already in use

This is because the previous execution has left the socket in a
TIME_WAIT state,
and can’t be immediately reused.

There is a socket
<http://docs.python.org/library/socket.html#module-socket> flag
to set, in order to prevent this, socket.SO_REUSEADDR:

s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)s.setsockopt(socket.SOL_SOCKET,
socket.SO_REUSEADDR, 1)s.bind((HOST, PORT))

the SO_REUSEADDR flag tells the kernel to reuse a local socket in
TIME_WAIT state,
without waiting for its natural timeout to expire.

El 7 de junio de 2012 08:45, mauricio rodriguez <
rodriguez.mauricio55 en gmail.com> escribió:

> es la cantidad de datos que recibe o envía de un tirón ... no la totalidad
> del trafico sino el tamaño del paquete
>
> 2012/6/7 Diego Uribe Gamez <diego.uribe.gamez en gmail.com>
>
>> Estoy mirando una conexión por Soket y no logro entender que hace el buf?
>> que es lo que cambia? el numero que se le asigna es que?
>>
>> host = "localhost"
>>
>>
>>
>>
>>
>>
>> port = 21567
>>
>>
>>
>>
>>
>>
>> buf = 1024
>>
>>
>>
>>
>>
>>
>> data = ''
>>
>>
>>
>>
>>
>>
>> addr = (host, port)
>>
>>
>>
>>
>>
>>
>> UDPSock = socket(AF_INET, SOCK_DGRAM)
>>
>>
>> while (1):
>>
>>
>>
>>
>>
>>
>>   data, addr = UDPSock.recvfrom(buf)
>>
>>
>> --
>>  *Diego Alonso Uribe Gamez*
>> ------------------------------
>>
>> *Desarrollador web*
>>
>> Twitter: @DiegoUG <http://www.twitter.com/DiegoUG>
>>
>> Google+: http://gplus.to/diegoug
>> ------------------------------
>>
>>
>>
>> _______________________________________________
>> Python-es mailing list
>> Python-es en python.org
>> http://mail.python.org/mailman/listinfo/python-es
>> FAQ: http://python-es-faq.wikidot.com/
>>
>>
>
> _______________________________________________
> Python-es mailing list
> Python-es en python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>


-- 
 *Diego Alonso Uribe Gamez*
------------------------------

*Desarrollador web*

Twitter: @DiegoUG <http://www.twitter.com/DiegoUG>

Google+: http://gplus.to/diegoug
------------------------------
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20120607/e1b4e73d/attachment.html>


Más información sobre la lista de distribución Python-es