Skynet

          ---------- ---------- 我的新 blog : liukaiyi.cublog.cn ---------- ----------

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            112 Posts :: 1 Stories :: 49 Comments :: 0 Trackbacks

          telnet 192.168.101.103 8014
          import threading  

          class myThread(threading.Thread):
              
          def __init__(self,conn,add):
                  threading.Thread.
          __init__(self)
                  self.inputstr 
          = ''
              self.connection
          =conn
              self.address
          =add
              
          def run(self):
              ii
          =0
                  
          while True:
                  self.connection.settimeout(
          50)
                      buf 
          = self.connection.recv(1024)
                  
          if  buf.rfind("\n"> -1 :  
                          
          print "**-"+self.inputstr
                          self.connection.close() 
                          
          break
                      
          else:  
                          self.inputstr
          +=buf
                  
          if ii==0:
                      self.connection.send(buf)
                  ii
          +=1
                          
          continue

                      
                      


          if __name__ == '__main__':  
             
          import socket  
             sock 
          = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
             sock.bind((
          '192.168.101.103'8014))  
             sock.listen(
          5)
             
          while True:  
                 
          try:
                     connection,address 
          = sock.accept()
                     ithread
          =myThread(connection,address)
                     ithread.start()
                 
          except socket.timeout:  
                     
          print 'time out'  





          整理 www.aygfsteel.com/Good-Game
          posted on 2009-10-27 19:16 劉凱毅 閱讀(1865) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): python
          主站蜘蛛池模板: 达拉特旗| 商城县| 杭州市| 甘肃省| 明星| 华宁县| 遂溪县| 昌乐县| 唐海县| 小金县| 万年县| 海兴县| 齐齐哈尔市| 海原县| 阿拉善左旗| 台东县| 镇坪县| 灵川县| 固始县| 和林格尔县| 东安县| 乌兰浩特市| 襄汾县| 宜良县| 丽江市| 崇信县| 墨江| 彭阳县| 绥滨县| 论坛| 龙山县| 扎鲁特旗| 佳木斯市| 会泽县| 泾源县| 深水埗区| 新安县| 璧山县| 赞皇县| 蒙城县| 夏津县|