【2013】实习收获2:python的网络编程--client端与server端入门(client端)
来源:互联网 发布:中国招标软件 编辑:程序博客网 时间:2024/06/04 18:31
(1) build a socket
At first, we need to build a socket, here is an example
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1). socket is the module for internet programming, which is already built in python
2).To build a socket, we need specify type and family.
in here socket.AF_INET is the type, which means the type is IPv4.
SOCK_STREAM is the family, which presents TCP, a stream protocol.
if we want to build an UDP connection, the family should be SOCK_DGRAM.
(2) connection
Then we should do the connection, like this:
s.connect(("www.wxample.com:,80))
what I should remember is ("www.example.com",80) inside the fucntion connect() is atuple, which means is we records this information in an object, it should be const.
What does this tuple consists is ("domain name/ip addr", port number).
(3) utilities
After building the connection, we can use a sort of build-in functions to get informations or handle the connections.
s.getsockname() return the socket's name and port number like this ("10.28.0.11",49533).
s.getpeername() return the peer's name and port number in the same format as getsockname().
send and receive data: there are two ways to send and receive: socket object and file object
socket object: send(), sendto(), recv() and recvfrom(). Which are more easy to use with UDP.
file object: read(), write() and readline(). Which are more easy to use with TCP.
- 【2013】实习收获2:python的网络编程--client端与server端入门(client端)
- 【2013】实习收获3:python网络编程--client端与server端入门(server)
- Python案例-网络编程-socket入门-server&client
- mysql client与server端的通信协议
- java网络编程(Client/Server)基础知识
- client-server交互计算器-client端/Windows
- Socket网络编程之Client端
- Python socket ssl 的server端和client端程序
- 网络编程client和server
- minetest源码解析六:Client与Server数据传递(Client端)
- Python网络编程--TCP Client
- Python网络编程--UDP Client
- 实现Server和client端的通信
- RMI网络编程 重启server端程序,client端无法连接
- socket C/C++编程(7)server端读取client端键入的数据
- Linux网络编程--TCP网络编程基础(简单的server/client模型)
- JAVA 网络编程 Socket server client 编程
- 一个java网络编程Socket的例子,实现Server与Client聊天
- mysql 存储过程-动态表名
- .NET强签名及混淆解决方案
- WinCE如何使用PictureBox的Image属性通过图片路径显示图片
- LFS<0531-1>
- Ubuntu下为Firefox安装Adobe Flash Player
- 【2013】实习收获2:python的网络编程--client端与server端入门(client端)
- RTMP流媒体播放之red5
- HttpClient 4.x 执行网站登录并抓取网页的代码
- 根目录index.php->wp-blog-header.php->wp-load.php->wp-config.php
- My Perosonal Folders 在 DevTrack 产品里的妙用
- flex Graphics例子
- 第十二堂作业
- OBIEE 11g 启动与停止包含服务器重启
- 使用HttpClient远程抓取网页内容