Python 网络编程
服务端代码:
import socket server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((‘127.0.0.1‘, 8080)) server.listen(1) while True: conn, addr = server.accept() print(addr) data = conn.recv(1024) print(data) conn.send(b‘This is server.‘) conn.close()
客户端代码:
import socket client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((‘127.0.0.1‘, 8080)) client.send(b‘Who are you?‘) data = client.recv(1024) print(data) client.close()
相关推荐
架构技术交流 2020-04-14
kikaylee 2020-03-03
Unimen 2020-06-25
MAC2007 2020-06-06
安辉 2020-05-05
diediexiaomi 2020-04-21
taishanduba 2020-04-11
kkpiece 2020-03-03
vanturman 2020-02-10
朱建伟 2020-01-10
jackalwb 2020-01-01
TinyDolphin 2020-01-10
shengge0 2020-01-08
apowerfulman 2020-01-07
OwenJi 2019-12-29
HongKongPython 2019-12-29
htofly 2019-12-16