当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.getID方法代码示例

本文整理汇总了Python中configuration.Configuration.getID方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.getID方法的具体用法?Python Configuration.getID怎么用?Python Configuration.getID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configuration.Configuration的用法示例。


在下文中一共展示了Configuration.getID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TCPSend

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def TCPSend(dest, content):
    TCP_IP = Configuration.getIP(dest) 
    MYIP = Configuration.getPublicIP()
    if TCP_IP == MYIP:
       print "TCPSend() terminates. (Error: sending to itself)" #Ignore itself
       return
    TCP_PORT = Configuration.TCPPORT 
    ID = Configuration.getMyID()
    print threading.currentThread().getName(), 'TCP Client Starting. I am Node#', ID
    BUFFER_SIZE = 1024
    MESSAGE = "Hello, World! from Node#%d" % ID
    
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    flag = True
    while flag:
        try:
            s.connect((TCP_IP, TCP_PORT))
            s.send(content)
            printdata("TCP Send", ID, ID, Configuration.getID(TCP_IP), content)
            data = s.recv(BUFFER_SIZE)
            s.close()
            flag = False
        except:
            printdata("TCP Client Reconnect", ID, ID, Configuration.getID(TCP_IP), "@[email protected]")
            time.sleep(1) #Reconnect delay 
    time.sleep(5)
    
    print threading.currentThread().getName(), 'TCP Client Exiting Successfully. I am Node #', ID
    return 
开发者ID:xil12008,项目名称:paxos,代码行数:31,代码来源:network.py

示例2: TCPClient

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def TCPClient():
    MYIP = Configuration.getPublicIP()
    ID = Configuration.getMyID()
    print threading.currentThread().getName(), 'TCP Client Starting. I am Node#', ID

    while True:
        user_input = raw_input("format: send <Dest Node ID> <Message>")
        cmd = user_input.split(" ")
        for ip in Configuration.IPTABLE:
            if ip == MYIP: continue #Ignore itself
            TCP_IP = ip 
            TCP_PORT = Configuration.TCPPORT 
            BUFFER_SIZE = 1024
            MESSAGE = "Hello, World! from Node#%d" % ID
        
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            flag = True
            while flag:
                try:
                    s.connect((TCP_IP, TCP_PORT))
                    s.send(MESSAGE)
                    printdata("TCP Send", ID, ID, Configuration.getID(TCP_IP), MESSAGE)
                    data = s.recv(BUFFER_SIZE)
                    s.close()
                    flag = False
                except:
                    printdata("TCP Client Reconnect", ID, ID, Configuration.getID(TCP_IP), "@[email protected]")
                    time.sleep(1) #Reconnect delay 
        time.sleep(5)
    
    print threading.currentThread().getName(), 'TCP Client Exiting. I am Node #', ID
    return
开发者ID:xil12008,项目名称:paxos,代码行数:34,代码来源:network.py

示例3: acceptor_udp_server

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def acceptor_udp_server():
    ID = Configuration.getMyID()
    #UDP_PORT = Configuration.ACCEPTOR_PORT
    UDP_PORT = Configuration.PORTS["prepare"]
    print threading.currentThread().getName(), ' Acceptor UDP Server Starting. I am Node#', ID, "at port", UDP_PORT

    sock = socket.socket(socket.AF_INET, # Internet
                         socket.SOCK_DGRAM) # UDP
    sock.bind(('', UDP_PORT))

    while True:
        data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
        peerID = Configuration.getID( addr[0] )
        #try
        json_object = transferInput(data)
        if json_object['msgname'] == "commit": 
           onCommit(json_object['entryID'], json_object['msglist'], peerID) 
           printdata("Acceptor Recv Commit", ID, peerID, ID, data)
        elif json_object['msgname'] == "accept":
           onAccept(json_object['entryID'], json_object['msglist'], peerID) 
           printdata("Acceptor Recv Accept", ID, peerID, ID, data)
        elif json_object['msgname'] == "prepare":
           onPrepare(json_object['entryID'], json_object['msglist'], peerID) 
           printdata("Acceptor Recv Prepare", ID, peerID, ID, data)
        #except:
        #    print "Can't parse data:", data, sys.exc_info()[0]
    print threading.currentThread().getName(), ' Acceptor UDP Server Exiting. I am Node#', ID
    return
开发者ID:xil12008,项目名称:paxos,代码行数:30,代码来源:acceptor.py

示例4: udp_send

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def udp_send(entryID, msgname, msglist, peerID): 
    ID = Configuration.getMyID()
    UDP_IP = Configuration.getIP(peerID) 
    UDP_PORT = Configuration.PORTS[msgname]
    msg = {}
    msg['msgname'] = msgname 
    msg['entryID'] = str( entryID ) 
    msg['msglist'] = msglist 
    MESSAGE = json.dumps(msg) 
    printdata("UDP Send " + msgname, ID, ID, Configuration.getID( UDP_IP ) , MESSAGE )
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
    sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
开发者ID:xil12008,项目名称:paxos,代码行数:14,代码来源:acceptor.py

示例5: UDPServer

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def UDPServer():
    ID = Configuration.getMyID()
    print threading.currentThread().getName(), 'UDP Server Starting. I am Node#', ID
    UDP_PORT = Configuration.UDPPORT 

    sock = socket.socket(socket.AF_INET, # Internet
                         socket.SOCK_DGRAM) # UDP
    sock.bind(('', UDP_PORT))

    while True:
        data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
        printdata("UDP Recv", ID, Configuration.getID( addr[0] ) , ID, data )
    print threading.currentThread().getName(), 'UDP Server Exiting. I am Node#', ID
    return
开发者ID:xil12008,项目名称:paxos,代码行数:16,代码来源:network.py

示例6: TCPServer

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def TCPServer():
    ID = Configuration.getMyID()
    MYIP = Configuration.getPublicIP()
    print threading.currentThread().getName(), 'TCP Server Starting. I am Node#', ID, "ip=", MYIP
    TCP_PORT = Configuration.TCPPORT 
    BUFFER_SIZE = 1024  # Normally 1024, but we want fast response

    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.bind(( socket.gethostname(), TCP_PORT))
    server.listen(5) #At most 5 concurrent connection
    input = [server] 
    running = 1 
    while running: 
        inputready,outputready,exceptready = select.select(input,[],[]) 
    
        for s in inputready: 
            if s == server: 
                # handle the server socket 
                client, address = server.accept() 
                input.append(client) 
                print 'TCP Server NODE#', ID,'<-----connect-----> NODE#' , Configuration.getID(address[0]) , "TCP Client (", len(input) - 2, "over", Configuration.getN() - 1, "connections)"
    
            else: 
                # handle all other sockets 
                data = s.recv(BUFFER_SIZE) 
                printdata("TCP Recv", ID, Configuration.getID(s.getpeername()[0]), ID, data)
                if data: 
                    s.send(data) 
                else: 
                    print "LOST CONNECTION FROM NODE#%d :  %s" %(Configuration.getID(s.getpeername()[0]), s.getpeername())
                    s.close() 
                    input.remove(s) 
    server.close()

    print threading.currentThread().getName(), 'TCP Server Exiting. I am NODE#', ID
    return
开发者ID:xil12008,项目名称:paxos,代码行数:38,代码来源:network.py

示例7: UDPClient

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getID [as 别名]
def UDPClient():
    ID = Configuration.getMyID()
    print threading.currentThread().getName(), 'UDP Client Starting. I am Node#', ID
  
    for ip in Configuration.IPTABLE:
        UDP_IP = ip
        UDP_PORT = Configuration.UDPPORT 
        MESSAGE = "Hello, World! from node %d" % ID 

        #print "UDP target IP:", UDP_IP
        #print "UDP target port:", UDP_PORT
        #print "UDP sending message:", MESSAGE
        printdata("UDP Send ", ID, ID, Configuration.getID( UDP_IP ) , MESSAGE )
        sock = socket.socket(socket.AF_INET, # Internet
                             socket.SOCK_DGRAM) # UDP
        sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
    print threading.currentThread().getName(), 'UDP Client Exiting. I am Node#', ID
    return
开发者ID:xil12008,项目名称:paxos,代码行数:20,代码来源:network.py


注:本文中的configuration.Configuration.getID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。