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


Python Configuration.getIP方法代码示例

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


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

示例1: TCPSend

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getIP [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: udp_send

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getIP [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

示例3: sendEvent

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import getIP [as 别名]
 def sendEvent(self):
     print "sendEvent: wait4leader"
     self.wait4leader()
     if conf.leader==-1 : return False
     self.UDP.send(conf.getIP(conf.leader),"event",str(self.event))
     data,addr = self.UDP.recv('', "complete")
     if data == None : 
         print "\033[94m Please wait. (due to leader dies, no majority of accepter found or just network problems.)"
         print "-"*20 + '\033[0m'
         return False
     #print "send event done, recved:", data, "from", addr
     self.remoteView(data)
     return True
开发者ID:xil12008,项目名称:paxos,代码行数:15,代码来源:consumer.py


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