资源简介
server.c 是echo server
sample.py 示例代码
说明
http://blog.csdn.net/hnmsky/article/details/20124615
代码片段和文件信息
#Fish:control monitor to drain water
import sys time
from socket import *
class SockUdp:
def __init__(selfip port):
self.sock = socket(AF_INET SOCK_DGRAM)
self.addr = (ip port)
self.sock.settimeout(5)
print(‘init‘)
def sendto(self buf):
#try:
self.sock.sendto(buf self.addr)
def recvfrom(self):
buf addr = self.sock.recvfrom(1024)
print(addr)
return buf
on = bytearray([0x5a0xa50xaa0x550x5a0xa50xaa0x550x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00])
off = bytearray([0x5a0xa50xaa0x550x5a0xa50xaa0x550x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00])
def switch(op):
print(‘switch:‘ + op)
s = SockUdp(‘192.168.1.2‘ 80)
for i in range(3):
if op == ‘on‘:
s.sendto(on)
else:
s.sendto(off)
#print(on)
s.recvfrom()
s.sock.close()
if __name__ == ‘__main__‘:
switch(‘on‘)
#switch(‘off‘)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1118 2014-06-01 23:37 sample.py
文件 1282 2014-04-28 20:10 server.c
评论
共有 条评论