Python's humble version of a one-to-one chat tool, full duplex

Source: Internet
Author: User

Good time to go to bed, tomorrow also to work ~ ~ Directly on the code, and then summarized

1 ImportThreading2 ImportOS3 ImportSocket4 5 6 defrecvprocess (Udp_socket, localaddrinfo):7     Print 'UDP Recver is up'8      while1:9data, peeraddr = Udp_socket.recvfrom (1024 )Ten         ifdata = ='Local Exit'  andLocaladdrinfo = =peeraddr: One             Print 'Recvprocess was terminated!' A              Break -         #data = Raw_input () -         Print '%s (Messagefrom%s:%d)'% (data, peeraddr[0], peeraddr[1] ) the  - if __name__=='__main__': -     #Create UDP Socekt -s =Socket.socket (socket.af_inet, socket. SOCK_DGRAM) +     #Get Local Machine name -MyName =Socket.getfqdn (Socket.gethostname ()) +MYADDR =socket.gethostbyname (myname) AAddrinfo = (myaddr, 5060 ) at     Printmyaddr - S.bind (addrinfo) -     #Start the RECV process -THREADRECV = Threading. Thread (target = recvprocess, args =(S, addrinfo)) - Threadrecv.start () -      while1: inval =raw_input () -         ifval = ='Exit': toS.sendto ('Local Exit', Addrinfo) +              Break -S.sendto (Val, ('192.168.3.36', 5060) ) the     Print 'quit'

Python's humble version of a one-to-one chat tool, full duplex

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.