Applications of socket and multithreading in Python

Source: Internet
Author: User
This is a small Socket Application I wrote before, and I also used a little bit of multithreading.
This Socket Client is a small application I wrote to facilitate the company's recharge system debugging. It communicates with the recharge system to automatically complete the recharge test.
 
ViewCodeRight:
 Import Socket, thread Def Communicate (s): phoneno = Raw_input (" Please input your phoneno. :( push enter to use default) ") # Get local phoneno If (LEN (phoneno) = 0: phoneno = '000000' phoneno =" Phone: "+ Phoneno # Add Prefix Of phoneno S. Send (phoneno) # SendData   String To Server Print '> % S' % phoneno Data = S. Recv (4096) # Get Response Data From Server Print '<% S' % Data #0819022324 process_string = '* 571253*0861235468*1*2617*3 #'s. Send (process_string) Print '> % S' % process_string Print '<% S' % S. Recv (4096) S. Send ('20140901 ') Print '> % S' %' 6506'Print '<% S' % S. Recv (4096) s. Close () # Disconnect the socket connection Print 'End! '# End the program Def Refill (): S = socket. socket (socket. af_inet, socket. sock_stream) # create a socket try: # S. connect (socket. gethostname (), 8888) # connect to target server S. connect ('2017. 168.4.129 ', 8888) # connect to target server failed t: Print " Connect to '% s' failed! "% (Socket. gethostname ()) Else : # Communicate (s) thread. start_new_thread (communicate, (S,) # socket communicate onNew Thread. Print " ----------------------------------------------------------- " Print " Welcom to use Python socket tools. sockettest. py \ nthis program is designed to test frs4 socket communicate test \ n ---- powered by lucker. " If (_ Name __= =' _ Main __ '): Refill ()
 
Conclusion
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.