本文整理汇总了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
示例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))
示例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