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

mauricio rodriguez rodriguez.mauricio55 en gmail.com
Jue Jun 7 17:52:10 CEST 2012


La documentación especifica mas coas que te has salteado

socket.recv(*bufsize*[,
*flags*])¶<http://docs.python.org/library/socket.html#socket.socket.recv>

Receive data from the socket. The return value is a string representing the
data received. The maximum amount of data to be received at once is
specified by *bufsize*. See the Unix manual page *recv(2)* for the meaning
of the optional argument *flags*; it defaults to zero.

Note


For best match with hardware and network realities, the value of
*bufsize* should
be a relatively small power of 2, for example, 4096.

Todos los datos que se envían a través de Internet son
"siempre" partidos en partes mas pequeñas
llamados paquetes, esto se debe a que así funciona el protocolo TCP
y también UDP,
independientemente de la aplicación.

http://es.wikipedia.org/wiki/Paquete_de_datos
http://es.wikipedia.org/wiki/Modelo_OSI
http://es.wikipedia.org/wiki/Conmutaci%C3%B3n_de_paquetes
http://es.wikipedia.org/wiki/Datagrama
http://es.wikipedia.org/wiki/Capa_de_transporte


2012/6/7 Diego Uribe Gamez <diego.uribe.gamez en gmail.com>

> Pero nada, no se como usarlo.
>
> 2012/6/7 Diego Uribe Gamez <diego.uribe.gamez en gmail.com>
>
>> 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
>> ------------------------------
>>
>>
>>
>
>
> --
>  *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/
>
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://mail.python.org/pipermail/python-es/attachments/20120607/77969475/attachment.html>


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