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


Python Configuration.getPublicIP方法代码示例

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


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

示例1: TCPSend

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

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


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