首页 > 代码库 > socket
socket
###########################
server端:
import socket
server= socket.socket()
server.bind((‘localhost‘,6969))
server.listen()
print("等电话")
conn,addr=server.accept()
print(conn,addr)
print("来了")
data = http://www.mamicode.com/conn.recv(1024)
print("recv:",data)
conn.send(data.upper())
server.close()
###########################
client端:
import socket
client = socket.socket()
client.connect((‘localhost‘,6969))
client.send(b"hello world")
data = http://www.mamicode.com/client.recv(1024)
print("recv:",data)
client.close()
#########################
#########################
client端:
####
import socket
client = socket.socket()
client.connect((‘10.0.0.11‘,6969))
while True:
msg=input(">>:").strip()
client.send(msg.encode(‘utf8‘))
data = http://www.mamicode.com/client.recv(1024)
print("recv:", data)
client.close()
####
server端:
####
import socket
server= socket.socket()
server.bind((‘10.0.0.11‘,6969))
server.listen()
print("等电话")
conn,addr=server.accept()
print(conn,addr)
print("来了")
while True:
data = http://www.mamicode.com/conn.recv(1024)
print("recv:", data.decode())
conn.send(data.upper())
server.close()
socket