Example #1
0
            trips['avg'] = (trips['avg'] + trips[last_trip]) / 2

    ## Increment Trip Counter
    trips[current_trip] = trips[current_trip] + 1

    ## Update Max
    if trips[current_trip] > trips['max']:
        trips['max'] = trips[current_trip]

    print(message)

    pubnub.publish({
        'channel':
        crazy,
        'message':
        current_trip + " Trip: " + str(trips[current_trip]) + " MAX: " +
        str(trips['max']) + "/sec " + " AVG: " + str(trips['avg']) + "/sec"
    })


pubnub.subscribe({
    'channel': crazy,
    'connect': connected,
    'callback': received
})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
pubnub.start()
Example #2
0
          ) % {
          'max': trips['max'],
          'avg': trips['avg'],
          'publishes': analytics['publishes'],
          'received': analytics['received'],
          'successful_publishes': analytics['successful_publishes'],
          'failed_publishes': analytics['failed_publishes'],
          'failed_deliveries': analytics['failed_deliveries'],
          'publishes': analytics['publishes'],
          'deliverability': analytics['deliverability'],
          'queued': analytics['queued']
          })
    pubnub.timeout(show_status, 1)


def connected():
    show_status()
    pubnub.timeout(send, 1)

print("Connected: %s\n" % origin)
pubnub.subscribe({
    'channel': channel,
    'connect': connected,
    'callback': received
})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
pubnub.start()

## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Ready to Receive Requests
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReady(message):
    print("Ready to Receive Requests on '%s'" % server_channel)


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Network Recovered
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReconnect(message):
    print("RECONNECTED")


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Network Failed
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onDisconnect(message):
    print("DISCONNECTED")


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Start Echo Server
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub.subscribe(
    server_channel, callback=onRequest, error=error_log, connect=onReady, reconnect=onReconnect, disconnect=onDisconnect
)
pubnub.start()
Example #4
0
    trips[current_trip] = trips[current_trip] + 1

    ## Update Max
    if trips[current_trip] > trips["max"]:
        trips["max"] = trips[current_trip]

    print(message)

    pubnub.publish(
        {
            "channel": crazy,
            "message": current_trip
            + " Trip: "
            + str(trips[current_trip])
            + " MAX: "
            + str(trips["max"])
            + "/sec "
            + " AVG: "
            + str(trips["avg"])
            + "/sec",
        }
    )


pubnub.subscribe({"channel": crazy, "connect": connected, "callback": received})

## -----------------------------------------------------------------------
## IO Event Loop
## -----------------------------------------------------------------------
reactor.run()
Example #5
0
        # Average
        if last_trip in trips:
            trips['avg'] = (trips['avg'] + trips[last_trip]) / 2

    # Increment Trip Counter
    trips[current_trip] = trips[current_trip] + 1

    # Update Max
    if trips[current_trip] > trips['max']:
        trips['max'] = trips[current_trip]

    print(message)

    pubnub.publish(crazy, current_trip +
                   " Trip: " +
                   str(trips[current_trip]) +
                   " MAX: " +
                   str(trips['max']) +
                   "/sec " +
                   " AVG: " +
                   str(trips['avg']) +
                   "/sec", error=error)


pubnub.subscribe(crazy, received, connect=connected, error=error)

# -----------------------------------------------------------------------
# IO Event Loop
# -----------------------------------------------------------------------
pubnub.start()
    print(current_thread().getName() + ' , ' + 'received = ' + str(received))

    if received != message:
        print('********** MISSED **************** ' + str(message - received))
    current = message


def connected_test(ch):
    print('Connected ' + ch)


def connected(ch):
    pass


'''
pubnub.subscribe({
    'channel'  : 'abcd1',
    'connect'  : connected,
    'callback' : message_received
})
'''


def cb1():
    pubnub.subscribe({
        'channel': 'efgh1',
        'connect': connected,
        'callback': message_received
    })
Example #7
0
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReady(message):
    print("Ready to Receive Requests on '%s'" % server_channel)
    request()


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Network Recovered
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReconnect(message):
    print("RECONNECTED")


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Network Failed
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onDisconnect(message):
    print("DISCONNECTED")


## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Start Echo Server
## =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub.subscribe(client_channel,
                 callback=onResponse,
                 error=error_log,
                 connect=onReady,
                 reconnect=onReconnect,
                 disconnect=onDisconnect)
pubnub.start()
Example #8
0
    request()


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Network Recovered
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReconnect(message):
    print("RECONNECTED")


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Network Failed
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onDisconnect(message):
    print("DISCONNECTED")


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Start Echo Server
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub.subscribe(
    client_channel,
    callback=onResponse,
    error=error_log,
    connect=onReady,
    reconnect=onReconnect,
    disconnect=onDisconnect
)

pubnub.start()
Example #9
0
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReady(message):
    print("Ready to Receive Requests on '%s'" % server_channel)


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Network Recovered
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onReconnect(message):
    print("RECONNECTED")


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Network Failed
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
def onDisconnect(message):
    print("DISCONNECTED")


# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Start Echo Server
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
pubnub.subscribe(server_channel,
                 callback=onRequest,
                 error=error_log,
                 connect=onReady,
                 reconnect=onReconnect,
                 disconnect=onDisconnect)

pubnub.start()
Example #10
0
    # New Trip Span (1 Second)
    if current_trip not in trips:
        trips[current_trip] = 0

        # Average
        if last_trip in trips:
            trips['avg'] = (trips['avg'] + trips[last_trip]) / 2

    # Increment Trip Counter
    trips[current_trip] = trips[current_trip] + 1

    # Update Max
    if trips[current_trip] > trips['max']:
        trips['max'] = trips[current_trip]

    print(message)

    pubnub.publish(crazy,
                   current_trip + " Trip: " + str(trips[current_trip]) +
                   " MAX: " + str(trips['max']) + "/sec " + " AVG: " +
                   str(trips['avg']) + "/sec",
                   error=error)


pubnub.subscribe(crazy, received, connect=connected, error=error)

# -----------------------------------------------------------------------
# IO Event Loop
# -----------------------------------------------------------------------
pubnub.start()
Example #11
0
                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on)

channel = 'a'


# Asynchronous usage
def callback(message, channel):
    print(message)


def error(message):
    print("ERROR : " + str(message))


def connect(message):
    print("CONNECTED")


def reconnect(message):
    print("RECONNECTED")


def disconnect(message):
    print("DISCONNECTED")


pubnub.subscribe(channel, callback=callback, error=callback,
                 connect=connect, reconnect=reconnect, disconnect=disconnect)

pubnub.start()
Example #12
0
    print(current_thread().getName(), ' , ', 'received = ', received)

    if received != message:
        print('********** MISSED **************** ', message - received)
    current = message


def connected_test(ch):
    print('Connected', ch)


def connected(ch):
    pass


'''
pubnub.subscribe({
    'channel'  : 'abcd1',
    'connect'  : connected,
    'callback' : message_received
})
'''


def cb1():
    pubnub.subscribe({
        'channel': 'efgh1',
        'connect': connected,
        'callback': message_received
    })