1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from vstf.common import constants
13 from vstf.common import message
16 class UdpServer(object):
18 super(UdpServer, self).__init__()
20 os.unlink(constants.sockaddr)
22 if os.path.exists(constants.sockaddr):
23 raise Exception("socket not found %s" % constants.sockaddr)
24 self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
26 def listen(self,backlog=5):
27 self.conn.listen(backlog)
30 return self.conn.accept()
32 def bind(self, addr=constants.sockaddr):
33 return self.conn.bind(addr)
35 # def send(self, data, addr):
36 # return message.sendto(self.conn.sendto, data, addr)
38 # def recv(self, size=constants.buff_size):
39 # return message.recv(self.conn.recvfrom)
45 class UdpClient(object):
47 super(UdpClient, self).__init__()
48 if not os.path.exists(constants.sockaddr):
49 raise Exception("socket not found %s" % constants.sockaddr)
50 self.conn=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
52 def connect(self, addr=constants.sockaddr):
53 return self.conn.connect(addr)
56 message.send(self.conn.send, data)
59 return message.recv(self.conn.recv)