socket-FTP-server

摘要:#!/usr/bin/env pythonimport commandsimport timeimport SocketServerclass MyTCPHandler(SocketServer.BaseRequestHandler):  defrecv_all(self,obj,msg_length,des_file):    while msg_length!=0:      if msg_length<=4096:        data =obj.recv(msg_length)   &nb

 socket-SSH模拟-client

摘要:#!/usr/bin/env pythonimport socketimport sys HOST,PORT="192.168.2.110",90sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect((HOST,PORT)) def recv_all(obj,msg_length):  raw_result = ''  while True:    if msg_length<=4096:      data =obj.recv(msg_length) &n

 socket-SSH模拟-server

摘要:#!/usr/bin/env pythonimport commandsimport timeimport SocketServerclass MyTCPHandler(SocketServer.BaseRequestHandler):   def handle(self):    print 'Got anew connection from',self.client_address    while True:      cmd  = self.request.recv(1024).strip()    &nb

 socket-多线程并发-client

摘要:#!/usr/bin/env pythonimport socketimport sys HOST,PORT="192.168.2.110",99sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)sock.connect((HOST,PORT)) while True:  data =raw_input('msg to send::').strip()  if len(data) ==0:continue sock.sendall(data+"\n")  received =sock.recv(1024)  print&qu

 socket-多线程并发-server

摘要:#!/usr/bin/env pythonimport SocketServerclass MyTCPHandler(SocketServer.BaseRequestHandler):   def handle(self):    print 'Got anew connection from',self.client_address    while True:      data =self.request.recv(1024).strip()      if not data:  &nbs

 socket-阻塞模式-client

摘要:#!/usr/bin/env pythonimport socketHOST='192.168.2.110'PORT=9002c=socket.socket(socket.AF_INET,socket.SOCK_STREAM)c.connect((HOST,PORT)) while True:  user_input =raw_input('msg to send::').strip() c.send(user_input)  return_data=c.recv(1024)  print'Received',return_datac.close() 

 socket-阻塞模式-server

摘要:实现了一对一的通信,如果另一个客户端来连接会阻塞(可以连接,但无法发送和接收数据)单进程串行执行#!/usr/bin/env pythonimport socketHOST='0.0.0.0'PORT= 9002s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.bind((HOST,PORT))s.listen(1)  while True: conn,addr=s.accept()   #accept()函数只接受一个用户连接,另一个用户连接会阻塞&

 socket-实例2-client

摘要:#!/usr/bin/env pythonimport socketHOST='192.168.2.110'PORT='50007's=socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.connect((HOST,PORT)) s.sendall('Hello,world')     #发送数据到server端data= s.recv(1024)           #收server端发过来的数据s.close()print 'Received',repr(data)

 socket-实例1-server

摘要:#!/usr/bin/env pythonimport socketHOST=''PORT= 50007s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)s.bind((HOST,PORT))s.listen(1)conn,addr=s.accept() #只接收一个客户端的连接        #conn客户端连接过来的实例        #addr客户端的IP地址 print 'Connectedby',addrwhile 1: 

 文档字符串

摘要:[root@localhostpython]# cat foo.py#!/usr/bin/env python"""foo.py--sample module demonstrating documentation strings"""class Foo(object):     """Foo() -empty class ... to bedeveloped"""def bar(x):     """bar(x) -function docstring for b
分页:« 1 2 3 4 5 6 7 8 9 »
Powered by AKCMS