diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 5c11852110eeb03dc5a69111354b383f98d15336 (patch) | |
tree | 7b26fde6effb80c241f28fc3e620016e7f86418e /tools/axl/udpServer.py | |
download | android_development-5c11852110eeb03dc5a69111354b383f98d15336.tar.gz android_development-5c11852110eeb03dc5a69111354b383f98d15336.tar.bz2 android_development-5c11852110eeb03dc5a69111354b383f98d15336.zip |
Initial Contribution
Diffstat (limited to 'tools/axl/udpServer.py')
-rwxr-xr-x | tools/axl/udpServer.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/axl/udpServer.py b/tools/axl/udpServer.py new file mode 100755 index 000000000..fc37ab85a --- /dev/null +++ b/tools/axl/udpServer.py @@ -0,0 +1,29 @@ +# UDP server example +import time, socket, string + +def main(): + + port = 9001 + buf = open("random.dat").read() + + svrsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + svrsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + svrsocket.bind(('', port)) + + # hostname = socket.gethostname() + hostname = "localhost" + ip = socket.gethostbyname(hostname) + print 'Server is at IP adress: ', ip + print 'Listening for requests on port %s ...' % port + + data, address = svrsocket.recvfrom(8192) + + count = 0 + while count < 500: + print 'Sending packet', count, 'to', address[0] + svrsocket.sendto("%3.3s%s" % (count, buf), address) + time.sleep(0.08) + count += 1 + +if __name__ == "__main__": + main() |