Exemplo n.º 1
0
def send_message(request):
    if not EM_INTERFACE.is_connected:
        success, err_msg = EM_INTERFACE.connect(request.user.username)
        if not success:
            Comet.push_message('Error connecting to event manager: ' + err_msg)
    
    if request.GET.has_key('message'):
        message = request.GET['message']
    else:
        logging.warning('Couldnt find message value in GET request')


    builder = EventMessageBuilder()
    
    builder.event_type = EventType.EVENT
    builder.event_name = EventList.TEXT_MESSAGE
    builder.client_name = request.user.username
    
    #Get robot name from database based on the username above
    # builder.event_destination = Database.getRobotNameFromUser(builder.client_name)
    builder.event_destination = 'client1'
    
    builder.event_content = EventMessage.MSG_ARG_DELIM + message + EventMessage.MSG_ARG_DELIM

    success, err_msg = EM_INTERFACE.send_raw_string(builder.build().toString())
    
    if not success:
        # Send error message to client!
        Comet.push_message('Error sending message: ' + err_msg)
    else:
        return HttpResponse("OK")
def send_message(request):
    if request.GET.has_key('message'):
        message = request.GET['message']
    else:
        logging.warning('Couldnt find message value in GET request')


    builder = EventMessageBuilder()
    
    builder.event_type = EventType.EVENT
    builder.event_name = EventList.TEXT_MESSAGE
    builder.client_name = 'tux'
    builder.event_destination = 'client1'
    builder.event_content = EventMessage.MSG_ARG_DELIM + message + EventMessage.MSG_ARG_DELIM

    success, err_msg = EM_INTERFACE.send_raw_string(builder.build().toString())
    
    if not success:
        # Send error message to client!
        Comet.push_message('Error sending message: ' + err_msg)
    else:
        return HttpResponse("OK")
Exemplo n.º 3
0
 
 #Get a new client instance    
 client = ClientConnection(config)
 
 #Initiate a connection between the client and the event manager.
 success, err_msg = client.connect()
 if not success:
     sys.stderr.write('Error connecting to event manager: ' + err_msg + '\n')
     sys.exit(1)
 
 #Write 5 messages
 for i in range(5):
     msg = raw_input("Enter a message to send: ")
     builder = EventMessageBuilder()
     builder.event_type = EventType.EVENT
     builder.event_name = EventList.TEXT_MESSAGE
     builder.client_name = config.client_name
     builder.event_destination = 'client1'
     builder.event_content = msg
     success, err_msg = client.send_raw_string(builder.build().toString())
     
     if not success:
         sys.stderr.write('Error sending message to event manager: ' + err_msg + '\n')
 
 #Disconnect from the client
 success, err_msg = client.disconnect()
 
 if not success:
     sys.stderr.write('Error disconnecting from event manager: ' + err_msg + '\n')
     sys.exit(1)