Add buffer to ouput
This commit is contained in:
parent
2ad6f4f110
commit
e573ab4d94
1 changed files with 32 additions and 9 deletions
41
client.py
41
client.py
|
|
@ -11,6 +11,20 @@ __author__ = "Jan Klopper <jan@underdark.nl>"
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
|
class MaxSizeList(list):
|
||||||
|
maxsize = 0
|
||||||
|
|
||||||
|
def __init__(self, maxcount=100):
|
||||||
|
self.maxsize = maxcount
|
||||||
|
super( MaxSizeList, self ).__init__()
|
||||||
|
|
||||||
|
def append(self, item):
|
||||||
|
super( MaxSizeList, self ).append(item)
|
||||||
|
if self.__len__() == self.maxsize:
|
||||||
|
raise IndexError('max size reached')
|
||||||
|
|
||||||
|
|
||||||
def RGBPixel(x, y, r, g, b, a=None): # pylint: disable=C0103
|
def RGBPixel(x, y, r, g, b, a=None): # pylint: disable=C0103
|
||||||
"""Generates the packed data for a pixel"""
|
"""Generates the packed data for a pixel"""
|
||||||
|
|
@ -28,15 +42,22 @@ def SetVersionBit(protocol=1):
|
||||||
|
|
||||||
def RandomFill(width=640, height=480):
|
def RandomFill(width=640, height=480):
|
||||||
"""Generates a random number of pixels with a random color"""
|
"""Generates a random number of pixels with a random color"""
|
||||||
message = SetRGBAMode(False)
|
message = MaxSizeList(140)
|
||||||
message += SetVersionBit()
|
message.append(SetRGBAMode(False))
|
||||||
|
message.append(SetVersionBit())
|
||||||
for pixel in xrange(0, random.randint(10, 100)):
|
for pixel in xrange(0, random.randint(10, 100)):
|
||||||
message += RGBPixel(random.randint(0, width),
|
pixel = RGBPixel(random.randint(0, width),
|
||||||
random.randint(0, height),
|
random.randint(0, height),
|
||||||
random.randint(0, 255),
|
random.randint(0, 255),
|
||||||
random.randint(0, 255),
|
random.randint(0, 255),
|
||||||
random.randint(0, 255))
|
random.randint(0, 255))
|
||||||
return message
|
try:
|
||||||
|
message.append(pixel)
|
||||||
|
except IndexError:
|
||||||
|
yield ''.join(message)
|
||||||
|
message[:] = []
|
||||||
|
message.append(pixel)
|
||||||
|
yield ''.join(message)
|
||||||
|
|
||||||
def SendPacket(ipaddress, port, message):
|
def SendPacket(ipaddress, port, message):
|
||||||
"""Sends the message to the udp server"""
|
"""Sends the message to the udp server"""
|
||||||
|
|
@ -50,7 +71,9 @@ def main():
|
||||||
port = 5005
|
port = 5005
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
SendPacket(ipaddress, port, RandomFill())
|
for packet in RandomFill():
|
||||||
|
time.sleep(0.01)
|
||||||
|
SendPacket(ipaddress, port, packet)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue