温馨提示:本文可能已经过时
XChat Client CLI
版本:pre-1
依赖
Python3(Tested 3.10.6)
rich
简介 XChat 是一个简单好用的聊天软件,它(指原版,给改了不关我事熬)不会收集任何除必须外的用户信息
测试服务器
IP:124.222.63.135
Port:19180
源代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 import socketfrom rich.console import Consoleimport threadingimport jsonimport timeconsole = Console() sock = None sockThread = None def send (data ): global sock sock.send( json.dumps(data).encode("utf-8" ) ) return json.loads( sock.recv(1024 ).decode("utf-8" ) ) def getMsg (): global sock, console while True : msg = send( { "mode" :"getMsg" , "data" :{} } ) try : for m in msg["data" ]["messages" ]: t = time.strftime( "%H:%M:%S" , time.localtime(m["time" ]) ) console.print ( f'[{t} ]<[yellow]{m["from" ]} [/]> {m["msg" ]} ' ) except : pass if __name__ == "__main__" : console.print ("[green]XChat CLI V1" ) sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) sock.connect( ( console.input ("[yellow]IP: " ), int (console.input ("[yellow]Port: " )) ) ) loginRecv = send( { "mode" :"login" , "data" :{ "username" :console.input ( "[yellow]User: " ) } } ) if loginRecv["code" ] == 200 : console.print ( "[green]Server connected!" ) sockThread = threading.Thread( None , getMsg ) sockThread.start() while True : sendMsg = console.input ("" ) send( { "mode" :"sendMsg" , "data" :{ "msg" :sendMsg } } )