Research Python server Development

Source: Internet
Author: User

研究python服务器开发http://www.example-code.com/python/ssh_exec.asp

telnet 118.193.152.71 51234
Importsocket, Threadinghost='127.0.0.1'PORT= 51234s=Socket.socket (socket.af_inet, socket. Sock_stream) S.bind ((HOST, PORT)) S.listen (4) Clients= []#List of clients connectedLock =Threading. Lock ()classChatserver (Threading. Thread):def __init__(self, (socket,address)): Threading. Thread.__init__(self) self.socket=Socket self.address=AddressdefRun (self): Lock.acquire () clients.append (self) lock.release ()Print '%s:%s connected.'%self.address whileTrue:data= SELF.SOCKET.RECV (1024)            if  notData: Break             forCinchclients:c.socket.send (data) self.socket.close ()Print '%s:%s disconnected.'%self.address Lock.acquire () clients.remove (self) lock.release () whileTrue:#wait for sockets to connect    #send socket to Chatserver and start monitoringChatserver (S.accept ()). Start ()


$ START "" .\dns-server.py$ .\dns-client.py172.16.45.84
#!/usr/bin/pythonImportSocketdefResolve (name):ifName = ="mpapp.nobies.in":        return "172.16.45.84"    Else :        #You ought to add some basic checking of the name here        returnSocket.gethostbyname (name) host="'Port= 50000Backlog= 5size= 1024s=Socket.socket (socket.af_inet, socket. Sock_stream) S.bind ((Host,port)) S.listen (backlog) while1: Client, Address=s.accept () data=client.recv (size)ifdata:bits= Data.split (":")        ifBits[0] = ='h': Client.send (Resolve (bits[1])) Client.close ()

#!/usr/bin/pythonImportSocket## # Configure me # # #dns_server_ip='127.0.0.1'Dns_server_port= 50000Query='mpapp.nobies.in' #Change this to the hostname-Want to lookup## # Configure me # # #size= 1024s=Socket.socket (socket.af_inet, socket. Sock_stream) S.connect ((Dns_server_ip,dns_server_port)) S.send ('h:'+query) Data=s.recv (size) s.close ()PrintData


Research Python server Development

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.