httpd服务和apache
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpd服务和apache相关的知识,希望对你有一定的参考价值。
套接字相关的系统调用:
socket(): 创建一个套接字
bind():绑定IP和端口
listen():监听
accept():接收请求
connect():请求连接建立
write():发送
read():接收
close():关闭连接
socket通信示例:
服务器端tcpserver.py
#/usr/bin/python
import socket
HOST=‘127.0.0.1‘
PORT=9527
BUFFER=4096
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.bind((HOST,PORT))
sock.listen(3)
print(‘tcpServer listen at: %s:%s\n\r‘ %(HOST,PORT))
while True:
client_sock,client_addr=sock.accept()
print(‘%s:%s connect‘ %client_addr)
while True:
recv=client_sock.recv(BUFFER)
if not recv:
client_sock.close()
break
print(‘[Client %s:%s said]:%s‘ %(client_addr[0],client_addr[1],recv))
client_sock.send(‘tcpServer has received your message‘)
sock.close()
客户端tcpclient
#/usr/bin/python
import socket
HOST=‘127.0.0.1‘
PORT=9527
BUFFER=4096
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((HOST,PORT))
sock.send(‘hello, tcpServer!‘)
recv=sock.recv(BUFFER)
print(‘[tcpServer said]: %s‘ % recv)
sock.close()
执行下面命令测试
python tcpserver
phthon tcpclient
以上是关于httpd服务和apache的主要内容,如果未能解决你的问题,请参考以下文章