2011-03-14 109 views
0

我試圖讓一些基本的網絡去python。下面是不實際的通信程序的片段:套接字程序掛起

客戶端

# open socket and connect to port 
      sock = socket(AF_INET, SOCK_STREAM) 
      sock.connect((regHost, regPort)) 

      # prepare flos for data 
      outFlo = sock.makefile(mode='w') 
      inFlo = sock.makefile(mode='r') 

      outFlo.write(queryString) 
      outFlo.flush() 
      print "finished writing" 

      tmp = inFlo.readline() 
      print tmp 

      outFlo.close() 
      inFlo.close() 
      sock.close() 

服務器端

 print 'Spawned thread' 
     inFlo = self.sock.makefile(mode='r') 
     outFlo = self.sock.makefile(mode='w') 

     outFlo.write('test writing\n') 
     outFlo.flush() 

     inFlo.close() 
     outFlo.close() 
     self.sock.close() 
     print 'Closed socket' 
     print 'Exiting thread' 

程序似乎是掛在調用inFlo。 readline()在客戶端。任何幫助將非常感激。

回答

1

錯誤在於我忘記在其中一個字符串的末尾添加\ n。因此,該程序掛在了對inFlo.readline()的調用中。