imalse / core / nodes /

"""This file defines the Client Command Meta Description"""

from core.cmd import CMD
from core.cmd.description import ClientDescription

class ClientCMD(CMD):
    This class is a subclass of CMD. It extends the default CMD with commands
    related to a client.
    name = 'client_cmd'
    def __init__(self, desc=None):
        if desc == None:
            desc = ClientDescription()
        CMD.__init__(self, desc)
        self.sock = None

    def srv_addr(self):
        """Returns the server address.""" 
        return self.desc.server_address
    def srv_port(self):
        """Returns the server port.""" 
        return self.desc.server_port

    def request_connect(self):
        """Request a connection to the server."""        
        sock = self.node.create_sock({'type':'server', 'proto':'tcp'})
        self.sock = sock
        if self.node.NODE_TYPE.startswith('real'):
            event = self.node.connect(sock, (self.srv_addr, self.srv_port))
        elif self.node.NODE_TYPE.startswith('sim'):
            event = self.node.connect(sock, (self.srv_addr, self.srv_port))

    def connection_refused(self):
        """Callback when a connection request has been refused by the server.""""connection_refused, try 2 seconds later")
        self.node.sleep(2, self.request_connect)

    def request_time_out(self):
        """Callback when a connection request has timed out""""request_time_out, try 2 seconds later")
        self.node.sleep(2, self.request_connect)

    def recv_disconn_req(self, sock):
        """Callback when a disconnect request from the server is received.""""recv_disconn_req")

    def recv_ack(self):
        """Callback when a 'ack' message is received from the server.""""connection constructed")
        print 'connection constructed'
        self.node.recv(self.sock, 512, self.dispatcher)

    def echo(self, sock, data):
        """Echo a message.""""receive echo message, [%s]" % (data.msg))
        print '-->', data.msg

    def start(self):
        This method overrides the one in CMD. Start by requesting a connection.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.