Exemplo n.º 1
0
    def send_packet(self, packet):
        self.UDPSock.settimeout(5)
        data = packet.pack()
        if (self.UDPSock.sendto(data, self.addr)):
            print "Sending message '", packet, "'....."
        print "Waiting for response..."

        data, srvaddr = self.UDPSock.recvfrom(buf)
        resp = easyip.Packet(data)
        print "%s as response" % resp
        print "errors=%r" % packet.response_errors(resp)
        return resp
 def _send_packet(self, packet):
     if not TESTING:
         data = packet.pack()
         self.FSTs.sendto(data, self.FST_addr)
         #  print "sending to", self.FST_addr
         print "in sendpacket,waiting for response..."
         data, srvaddr = self.FSTs.recvfrom(bufSize)
         resp = easyip.Packet(data)
         print "in senddpacket, response from Festo", resp
         if packet.response_errors(resp) is None:
             print "No send Errors"
         else:
             print "errors=%r" % packet.response_errors(resp)
         return resp
Exemplo n.º 3
0
 def _send_packet(self, packet):
     if not TESTING:
         data = packet.pack()
         #  print "sending to", self.FST_addr
         self.FSTs.sendto(data, self.FST_addr)
         if WAIT_FESTO_RESPONSE:
             #  print "in sendpacket,waiting for response..."
             data, srvaddr = self.FSTs.recvfrom(bufSize)
             resp = easyip.Packet(data)
             #  print "in senddpacket, response from Festo", resp
             if packet.response_errors(resp) is None:
                 self.netlink_ok = True
                 #  print "No send Errors"
             else:
                 self.netlink_ok = False
                 print "errors=%r" % packet.response_errors(resp)
         else:
             resp = None
         return resp
Exemplo n.º 4
0
 def react(self, packet):
     response = easyip.Packet()
     response.counter = packet.counter
     response.flags = 128
     return response
Exemplo n.º 5
0
        log.msg(msg, logLevel=logging.DEBUG)


class TwistedEasyS(protocol.DatagramProtocol):
    """
    Warning!!!
    This class is experimental and not tested
    """
    def __init__(self):
        #self.log = logging.getLogger('easyip.EasyS')
        self.log = LogProxy()

    def startProtocol(self):
        pass

    def sendMsg(self, packet, (host, port)):
        self.log.debug('Sending data')
        self.transport.write(packet.pack(), (host, port))

    def datagramReceived(self, datagram, (host, port)):
        packet = easyip.Packet(datagram)
        response = self.react(packet)
        if response:
            self.sendMsg(response, (host, port))

    def react(self, packet):
        response = easyip.Packet()
        response.counter = packet.counter
        response.flags = 128
        return response
Exemplo n.º 6
0
port = 1000 + easyip.EASYIP_PORT
buf = 1024
addr = (host, port)

# Create socket and bind to address
UDPSock = socket(AF_INET, SOCK_DGRAM)
UDPSock.bind(addr)

print "waiting"

# Receive messages
while 1:
    data, addr = UDPSock.recvfrom(buf)
    if not data:

        print "Client has exited!"
        break
    else:
        packet = easyip.Packet(data)
        print "\nReceived message '", packet, "' with %s" % (packet.payload, )
        response = easyip.Factory.response(packet)
        UDPSock.sendto(response.pack(), addr)
        print "Responded to %s, %s" % addr
        print "Putting incomming on queue"
        publisher.send({'address': addr, 'payload': packet.payload})

print "Closing"
# Close socket
UDPSock.close()
publisher.close()