blob: 6cb64193fcfca84e817bb8bbe7d14008147b0462 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
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
rdudyalab086cf32016-08-11 00:07:45 -040017import socket
18import msgpack
19from oslo_utils import units
20import logging
21UDP_IP = "10.11.10.1"
22UDP_PORT = 5006
23
24logging.basicConfig(format='%(asctime)s %(filename)s %(levelname)s %(message)s',filename='udp_client.log',level=logging.INFO)
25udp = socket.socket(socket.AF_INET, # Internet
26 socket.SOCK_DGRAM) # UDP
27udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
28udp.bind((UDP_IP, UDP_PORT))
29while 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