需求:SCIENCE 和MOOD两个人软件专业出身,厌倦了大众化的聊天软件,想着自己开发一款简易的聊天软件,满足他们的个性化需求,又不失“专业水准”,Talk is easy, try to code it.
技术:socket,详细了解请参考推酷:python socket
语言:python
尽管socket区分服务器和客户端,但是在聊天程序中两者是平等的关系,都是客户端程序。
Server.py
import socket
host = socket.gethostname()
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
s.listen(1)
sock,addr = s.accept()
print('Connection built')
info = sock.recv(1024).decode()
while info != 'exit':
print('MOOD:'+info)
send_mes = input()
sock.send(send_mes.encode())
if send_mes =='exit':
break
info = sock.recv(1024).decode()
sock.close()
s.close()
Client.py
import socket
s= socket.socket()
host = socket.gethostname()
port = 12345
s.connect((host,port))
print('Linked')
info = ''
while info != 'exit':
print('SCIENCE:'+info)
send_mes=input()
s.send(send_mes.encode())
if send_mes =='exit':
break
info = s.recv(1024).decode()
s.close()
恩,太low了有木有?连个图形化界面都没有,跟别谈其他个性化功能了。希望他们继续努力,早日做出属于他们自己的聊天软件吧!