网络接口api
2021-01-25 21:13
标签:接收 ndt pre add 自动 unix 系统 end 标准输入输出 系统调用过程中,其中和网络有关的系统调用信息如下: 可以从这些信息中看的python提供的网络接口API和Linux Socket API间一一对应的关系: 网络接口api 标签:接收 ndt pre add 自动 unix 系统 end 标准输入输出 原文地址:https://www.cnblogs.com/sylg12138/p/12005553.html#服务端
import socket,sys
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = socket.gethostname()
port = 8060
server.bind((host,port))
server.listen()
while True:
client,addr = server.accept()
print(‘连接地址:‘,str(addr))
while True:
data = client.recv(1024)
print(‘Client(reciver):‘,data.decode())
msg = input(‘Server(Send):‘)
client.send(msg.encode(‘utf-8‘))
client.close()
#客户端
import socket,sys
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = socket.gethostname()
port = 8060
client.connect((host,port))
while True:
msg = input(‘Client(Send):‘)
client.send(msg.encode(‘utf-8‘))
rec = client.recv(1024)
print(‘Server(reciver):‘,rec.decode())
client.close()
socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(1234), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 1), ...}) = 0
sendto(3, "Hello,I‘m liu", 13, 0, NULL, 0) = 13
recvfrom(3, "Hi,liu", 1024, 0, NULL, NULL) = 6
write(1, "Hi,liu\n", 7Hi,liu) = 7
close(3) = 0
下一篇:C#发送邮件