1#!/usr/bin/env python
2
3#
4# Copyright 2007, The Android Open Source Project
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19"""
20  udpEater.py: receives UDP traffic
21
22"""
23
24import time, socket, string
25
26def main():
27    port = 9001
28
29    svrsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
30    svrsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
31    svrsocket.bind(('', port))
32
33    hostname = socket.gethostname()
34    ip = socket.gethostbyname(hostname)
35    print 'Server is at IP adress: ', ip
36    print 'Listening for requests on port %s ...' % port
37
38    count = 0
39    while count < 400:
40        data, address = svrsocket.recvfrom(8192)
41        print 'Received packet', count, data[:34]
42        count += 1
43
44if __name__ == "__main__":
45    main()
46