摘要: 今天将python中socket模块的基本API学习完后,照着书上的实例编写一个套接字服务器和客户端。采用python3.5版本,在注释中会标明python2和python3的不同之处。 1.代码 (1)服务器端及对应代码解释 1 # ! /usr/bin/env python 2 # -*- co 阅读全文
posted @ 2016-09-26 21:07 欧阳逸轩 阅读(1461) 评论(0) 推荐(1) 编辑
摘要: 很多情况下,默认的套接字缓冲区大小可能不够用。此时,可以将默认的套接字缓冲区大小改成一个更合适的值。 1. 代码 2.setsockopt()和getsockopt() 3.AF_INET和SOCK_STREAM解释 4.运行结果 阅读全文
posted @ 2016-09-21 22:58 欧阳逸轩 阅读(10481) 评论(0) 推荐(0) 编辑
摘要: 在网络应用中,经常会遇到这种情况:一方尝试连接,但另一方由于网络媒介失效或者其他原因无法响应。 Python的Socket库提供了一个方法,能通过socket。error异常优雅地处理套接字错误。 1. 代码及相关解释 阅读全文
posted @ 2016-09-21 21:58 欧阳逸轩 阅读(3663) 评论(0) 推荐(0) 编辑
摘要: str内部功能详解: 阅读全文
posted @ 2016-09-17 20:42 欧阳逸轩 阅读(2547) 评论(0) 推荐(0) 编辑
摘要: Sometimes,you need to manipulate the default values of certain properties of a socket library, for example, the socket timeout. 设定并获取默认的套接字超时时间。 1.代码 阅读全文
posted @ 2016-09-16 21:45 欧阳逸轩 阅读(2038) 评论(0) 推荐(0) 编辑
摘要: If you ever need to write a low-level network application, it may be necessary to handle the low-level data transmission over the wire between two mac 阅读全文
posted @ 2016-09-16 00:37 欧阳逸轩 阅读(7257) 评论(0) 推荐(0) 编辑
摘要: 1.通过指定的端口和协议找到对应的服务名,采用socket中getservbyprot()函数实现。 2.输出结果 3.socket.getservbyport()解释 阅读全文
posted @ 2016-09-14 13:46 欧阳逸轩 阅读(1864) 评论(0) 推荐(0) 编辑
摘要: 1.将IPv4地址转换为32位二进制格式,用做底层网络函数。 2. .inet_aton()和inet_ntoa()及hexlify()解释 阅读全文
posted @ 2016-09-13 23:22 欧阳逸轩 阅读(1568) 评论(0) 推荐(0) 编辑
摘要: 有时需要把设备的主机名转换成对应的IP地址,下面是一个简单的操作。 运行结果: 1.域名正确返回对应的IP地址 $ python3 1_2_remote_machine_info.py IP address of www.python.org: 151.101.16.223 2.域名错误无法返回IP 阅读全文
posted @ 2016-09-13 13:19 欧阳逸轩 阅读(4393) 评论(0) 推荐(1) 编辑
摘要: 1.快速查看主机名和对应的IP地址小程序 2.关于gethostname()和gethostbyname()解释 阅读全文
posted @ 2016-09-13 13:18 欧阳逸轩 阅读(892) 评论(0) 推荐(0) 编辑