def main():
    if not common.validate_client_argv():
        return -1

    msg_generator = common.EchoGenerator(maxcount=common.LOOP_COUNT)
    history_container = common.TimeHistoryContainer()

    HOST = sys.argv[1]
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        sock.connect((HOST, common.SOCKET_PORT))
    except IOError:
        print >> sys.stderr, 'cannot connect'
        return -1

    while True:
        data = msg_generator()
        if len(data) == 0:
            break

        watch = common.StopWatch()
        sock.sendall(data)
        received = sock.recv(1024)
        latency = watch.stop()
        history_container.append(latency)
    sock.close()

    latency_list = history_container.get_stats_list(reverse=False)
    for x in latency_list:
        print x
Exemplo n.º 2
0
 def test_remove_first_last_enabled(self):
     container = common.TimeHistoryContainer()
     container.append(1)
     container.append(2)
     container.append(3)
     container.append(4)
     self.assertEqual([2, 3],
                      container.get_stats_list(remove_first_last=True))
Exemplo n.º 3
0
 def test_remove_first_last_disable(self):
     container = common.TimeHistoryContainer()
     container.append(1)
     container.append(2)
     container.append(3)
     container.append(4)
     self.assertEqual([1, 2, 3, 4],
                      container.get_stats_list(remove_first_last=False))
def main():    
    if not common.validate_client_argv():
        return -1    
    
    '''
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.sendto('test msg', (ip, PORT))
    '''
    HOST = sys.argv[1]

    # SOCK_DGRAM is the socket type to use for UDP sockets
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.settimeout(1);

    # As you can see, there is no connect() call; UDP has no connections.
    # Instead, data is directly sent to the recipient via sendto().
    msg_generator = common.EchoGenerator(maxcount=common.LOOP_COUNT)
    history_container = common.TimeHistoryContainer()
    while True:
        data = msg_generator()
        if len(data) == 0: 
            break

        try:
            watch = common.StopWatch()
            sock.sendto(data, (HOST, common.SOCKET_PORT))
            received = sock.recv(1024)
            latency = watch.stop()
            history_container.append(latency)
            #print "received [%s]" % received
        except socket.timeout:
            #print 'timeout'
            history_container.append(999)
    
    latency_list = history_container.get_stats_list(reverse=False)
    for x in latency_list:
        print x
Exemplo n.º 5
0
 def test_reverse_enabled(self):
     container = common.TimeHistoryContainer()
     container.append(1)
     container.append(3)
     container.append(2)
     self.assertEqual([3, 2, 1], container.get_stats_list(reverse=True))
Exemplo n.º 6
0
 def test_reverse_disabled(self):
     container = common.TimeHistoryContainer()
     container.append(1)
     container.append(3)
     container.append(2)
     self.assertEqual([1, 2, 3], container.get_stats_list(reverse=False))
Exemplo n.º 7
0
    sys.exit(0)

first_match = service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]

print >> sys.stderr, "connecting to \"%s\" on %s" % (name, host)

# Create the client socket
sock = BluetoothSocket(RFCOMM)
sock.connect((host, port))

#print "connected.  type stuff"
msg_generator = common.EchoGenerator(maxcount=common.LOOP_COUNT)
history_container = common.TimeHistoryContainer()
while True:
    data = msg_generator()
    if len(data) == 0:
        break

    watch = common.StopWatch()
    sock.send(data)
    data = sock.recv(1024)
    latency = watch.stop()
    history_container.append(latency)

sock.close()

latency_list = history_container.get_stats_list(reverse=False)
for x in latency_list: