In this article, the example of Python based on the Socket implementation of a simple chat program. Shared for your reference, as follows:
Demand:SCIENCE and MOOD are two people who majored in software and were tired of the popular chat software, and thought of developing a simple chat software by themselves to meet their individual needs without losing the "professional standard", Talk is easy, try to code it.
Technology:socket, see the previous section for details:Python Socket implementation of simple TCP Server/client functionality
Language:python
Although sockets distinguish between servers and clients, they are equal in chat programs and are both client programs.
import socket host = () port = 12345 s = (socket.AF_INET,socket.SOCK_STREAM) ((host,port)) (1) sock,addr = () print('Connection built') info = (1024).decode() while info != 'exit': print('MOOD:'+info) send_mes = input() (send_mes.encode()) if send_mes =='exit': break info = (1024).decode() () ()
import socket s= () host = () port = 12345 ((host,port)) print('Linked') info = '' while info != 'exit': print('SCIENCE:'+info) send_mes=input() (send_mes.encode()) if send_mes =='exit': break info = (1024).decode() ()
Screenshots of the effect:
Well, it's too low, isn't it? They don't even have a graphical interface, let alone other personalized features. Let's hope they will continue to work hard and make their own chat software soon!
More about Python related content can be viewed on this site's topic: thePython Socket Programming Tips Summary》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Summary of Python string manipulation techniques》、《Python introductory and advanced classic tutorialsand theSummary of Python file and directory manipulation techniques》
I hope that what I have said in this article will help you in Python programming.