易截截图软件、单文件、免安装、纯绿色、仅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中静态方法的实现

作者:老王
Python似乎很讨厌修饰符,没有常见的static语法。其静态方法的实现大致有以下两种方法:
第一种方式(staticmethod):
>>> class Foo:
        str = "I'm a static method."
        def ba ......

python hidden features

from http://stackoverflow.com/questions/101268/hidden-features-of-python
http://www.okpython.com/bbs/thread-3434-1-1.html
http://www.okpython.com/bbs/thread-3436-1-2.html
http://www.okpython.com/bbs/thread-3437-1-2.html
http://www.okpython.com/bbs/thread-3438-1-1.html
http://www.okpython.com/bb ......

对Python进程进行全解析

下面对Python进程进行深入而仔细的学习,首先先让大家了解下什么是Python进程,以及在对Python进程进行处理时注意的相关问题,接下来,就由我给大家进行介绍学习,仅供大家学习。
不过,虽然进程可在单独的内存空间中执行,但除非这些Python进程在单独的处理器上执行,否则,实际并不是“同时”运行的。是由操作 ......

python 2.4与2.5中字符串与datetime转换的区别

python 2.4中datetime有strftime方法而无strptime方法
而python2.5中这两个方法均有,而我的开发环境正好是python 2.5,而运行环境则是python 2.4
开发环境下调试好的程序,在服务器上就不run。查了一下python的官方文档
,斜体写着:New
in version 2.5.
不兼容的代码如下:
Python语言
:
test_strptime.py
res ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号