1、服务端
'''
时间:2020.10.18
作者:小宇
'''
import socket
import datetime
HOST = '0.0.0.0'
PORT = 3600
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #参数1表示ipv4,参数2表示指明tcp
s.bind((HOST,PORT))
s.listen(1)
while True:
conn,addr = s.accept()
print('from app %s connect !'%str(addr))
dt = datetime.datetime.now()
mes = str('severs ' + str(dt)).encode() #mes为发送至客户端的消息,此处转码
conn.send(mes) #piu,发送
print("sent to app message:",mes)
conn.close()
2、客户端
'''
时间:2020.10.18
作者:小宇
'''
import socket
import datetime
HOST = '0.0.0.0'
PORT = 3600
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #参数1表示ipv4,参数2表示指明tcp
s.bind((HOST,PORT))
s.listen(1)
while True:
conn,addr = s.accept()
print('from app %s connect !'%str(addr))
dt = datetime.datetime.now()
mes = str('severs ' + str(dt)).encode() #mes为发送至客户端的消息,此处转码
conn.send(mes) #piu,发送
print("sent to app message:",mes)
conn.close()