python udp c/s ¼Ç¼
server:
import sys
import socket
host = sys.argv[1]
port = int(sys.argv[2])
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host,port))
while 1:
try:
message, address = s.recvfrom(100)
print "Got data from", address, message
#cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#cs.sendto(message, address)
#cs.close()
s.sendto(message, address)
except (KeyboardInterrupt, SystemExit):
raise
except:
traceback.print_exc()
client:
import socket
import sys
import time
count = 0
while (count < 9):
try:
time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto("test", ("192.168.22.209", 1234))
data,addr = s.recvfrom(1024)
if data:
print 'received:',data,'from',addr
s.close()
except:
print 'except'
Ïà¹ØÎĵµ£º
ʵÔÚÎÞÁÄÖоͽ«ÔÀ´µÄһЩ¶«Î÷ÕûÀíÁËһϣ¬×Ô¼ºÊǸö¼ÇÐÔ²»ºÃµÄÈË£¬¸ô¶Ïʱ¼äÕûÀí×Ô¼º£¬Í¬Ê±Ò²Ï£Íû¿ÉÒÔ·½±ãËûÈË¡£
----------------------------------------------------------------------------------------------------------------------------------------
/**//*************************************************** ......
ÓÉÓÚLINUX
CûÓжÔ×Ö·û´®×Ó´®Ìæ»»¹¦ÄÜ,ËùÒÔÎÒ×Ô¼ºÐ´ÁËÒ»¸östr_replaceº¯Êý,ʵÏÖÁË×Ö·û´®Ìæ»».
Çë´ó¼Ò²Î¿¼.
/*
* FUNCTION : str_replace
*
ABSTRACT : replace child string in a string.
*
PARAMETER &nbs ......
±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍƼöµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔÊ ......
×÷ÕߣºÀÏÍõ
PythonËƺõºÜÌÖÑáÐÞÊηû£¬Ã»Óг£¼ûµÄstaticÓï·¨¡£Æ侲̬·½·¨µÄʵÏÖ´óÖÂÓÐÒÔÏÂÁ½ÖÖ·½·¨£º
µÚÒ»ÖÖ·½Ê½£¨staticmethod£©£º
>>> class Foo:
str = "I'm a static method."
def ba ......