摘要:
最近在做一个聊天室 用到了socket 遇到了struct模块,一查资料struct可用来来处理c语言中的结构体。struct模块中最重要的三个函数是pack(), unpack(), calcsize()pack(fmt, v1, v2, ...) 将python的值按照给定的格式(fmt),把数据封装成字符串(实际上是类似于c结构体的字节流)unpack(fmt, string) 按照给定的格式(fmt)解析字节流string,返回解析出来的tuple,转换成python数据类型元组calcsize(fmt) 计算给定的格式(fmt)占用多少字节的内存struct... 阅读全文
posted @ 2013-08-31 20:25
枫桦宁
阅读(294)
评论(0)
推荐(0)
摘要:
1 import socket 2 3 def get_constants(profix): 4 return dict((getattr(socket,n),n) 5 for n in dir(socket) 6 if n.startswith(profix) 7 ) 8 families=get_constants('AF_') 9 types=get_constants('SOCK_')10 protocols=get_constants('IPPROTO_')11 12 for ... 阅读全文
posted @ 2013-08-31 10:40
枫桦宁
阅读(201)
评论(0)
推荐(0)

浙公网安备 33010602011771号