易截截图软件、单文件、免安装、纯绿色、仅160KB

[转] 最简单的使用UDP通信的Python Socket例子

来源:http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
客户端程序代码:
# Client program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)
def_msg = "===Enter message to send to server===";
print "\n",def_msg
# Send messages
while (1):
data = raw_input('>> ')
if not data:
break
else:
if(UDPSock.sendto(data,addr)):
print "Sending message '",data,"'....."
# Close socket
UDPSock.close()
服务器端程序代码:
# Server program
from socket import *
# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)
# Receive messages
while 1:
data,addr = UDPSock.recvfrom(buf)
if not data:
print "Client has exited!"
break
else:
print "\nReceived message '", data,"'"
# Close socket
UDPSock.close()


相关文档:

python时间转为时间戳

找了半天没找着,终于在英文站点上找到,还有感谢群里的石头和球迷
>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0
别外付一个python对时间的一些函数,很好用的
我们先导入必须用到的一个module
>>> import time
设置一个时间的格式,下面会用到
& ......

python self __init__

self
类的方法与普通的函数只有一个特别的区别——它们必须有一个额外的第一个参数名称,但是
在调用这个方法的时候你不为这个参数赋值,Python会提供这个值。这个特别的变量指对象本
身,按照惯例它的名称是self。
这也意味着如果你有一个不需要参数的方法,你还是得给这个方法定义一个self参数。
__init_ ......

WebTrack 在 python bottle framework中的简单实现

网络臭虫亦即网络信标,是通过某种手段隐式获取信息的的方法。
在bottle framework中可用下面的方法实现:
首先在你要用户浏览器显示的页面tpl上嵌入一个1*1像素的图片,或更小。
这个图片地址指向你服务器上某个特定位置,如static/webtrack.png。
用户打开网页,就会访问这个图片(通过浏览器如http://abc.abc.com/st ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号