第八篇:socket网络编程
一、网络编程简绍
二、socket连接过程
三、socket文件传输
四、socket循环接收
五、socket粘包处理
六、FTP文件传输
七、socketServer
八、web框架
#!/usr/bin/env python
#WEB框架
import socket
def handle_request(client):
buf = client.recv(1024)
client.send(bytes("HTTP/1.1 200 OK\r\n\r\n",encoding='utf-8'))
client.send(bytes("Hello,Seven",encoding='utf-8'))
def main():
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind(('localhost',8000))
sock.listen(5)
while True:
connection,address = sock.accept()
handle_request(connection)
connection.close()
if __name__ == '__main__':
main()
实战练习:FTP服务器编写