2010-11-14 22:01:57 +01:00
|
|
|
# Client program
|
|
|
|
|
|
|
|
from socket import *
|
2010-11-15 12:44:10 +01:00
|
|
|
import sys
|
|
|
|
import time
|
2010-11-16 20:27:22 +01:00
|
|
|
import random
|
2010-11-14 22:01:57 +01:00
|
|
|
|
|
|
|
# Set the socket parameters
|
2010-11-15 12:44:10 +01:00
|
|
|
local_port = 5000 + int( sys.argv[1] )
|
|
|
|
remote_port = 4321
|
2010-11-14 22:01:57 +01:00
|
|
|
|
2010-11-15 12:44:10 +01:00
|
|
|
# TODO: autodetect interface address for remote application
|
|
|
|
outgoing_if = "127.0.0.1"
|
|
|
|
remote_host = "127.0.0.1"
|
|
|
|
|
|
|
|
# udp is the default for DGRAM
|
|
|
|
UDPSock = socket(AF_INET, SOCK_DGRAM)
|
|
|
|
UDPSock.bind((outgoing_if, local_port))
|
|
|
|
|
|
|
|
# we will not use connections so we can keep working even if the server
|
|
|
|
# goes down or refuses connection
|
|
|
|
#UDPSock.connect((remote_host, remote_port))
|
|
|
|
|
|
|
|
display = open('display', 'r')
|
2010-11-17 14:50:21 +01:00
|
|
|
z_buffer = chr(1) + "\n"
|
2010-11-15 12:44:10 +01:00
|
|
|
|
|
|
|
data = z_buffer + display.read()
|
2010-11-14 22:01:57 +01:00
|
|
|
|
2010-11-16 20:27:22 +01:00
|
|
|
random.seed()
|
|
|
|
|
2010-11-14 22:01:57 +01:00
|
|
|
# Send messages
|
2010-11-17 15:38:40 +01:00
|
|
|
sleeptime = 0.01
|
2010-11-16 20:27:22 +01:00
|
|
|
frequency = 1/sleeptime
|
|
|
|
i = random.randint(0,frequency-1)
|
2010-11-14 22:01:57 +01:00
|
|
|
while (1):
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
else:
|
2010-11-15 12:44:10 +01:00
|
|
|
UDPSock.sendto(data,(remote_host,remote_port))
|
2010-11-16 20:27:22 +01:00
|
|
|
#send ~100 packets per second
|
|
|
|
i+=1
|
|
|
|
time.sleep(sleeptime)
|
|
|
|
if i >= frequency:
|
|
|
|
time.sleep(3)
|
|
|
|
i = random.randint(0,frequency-1)
|
2010-11-14 22:01:57 +01:00
|
|
|
|
2010-11-15 12:44:10 +01:00
|
|
|
UDPSock.close()
|