Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
rdudyala | b086cf3 | 2016-08-11 00:07:45 -0400 | [diff] [blame] | 17 | import socket |
| 18 | import msgpack |
| 19 | from oslo_utils import units |
| 20 | import logging |
| 21 | UDP_IP = "10.11.10.1" |
| 22 | UDP_PORT = 5006 |
| 23 | |
| 24 | logging.basicConfig(format='%(asctime)s %(filename)s %(levelname)s %(message)s',filename='udp_client.log',level=logging.INFO) |
| 25 | udp = socket.socket(socket.AF_INET, # Internet |
| 26 | socket.SOCK_DGRAM) # UDP |
| 27 | udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 28 | udp.bind((UDP_IP, UDP_PORT)) |
| 29 | while True: |
| 30 | data, source = udp.recvfrom(64 * units.Ki) |
| 31 | #print data |
| 32 | #try: |
| 33 | sample = msgpack.loads(data, encoding='utf-8') |
| 34 | logging.info("%s",sample) |
| 35 | print sample |
| 36 | #except Exception: |
| 37 | #logging.info("%s",sample) |
| 38 | # print ("UDP: Cannot decode data sent by %s"), source |