我正在尝试在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()的调用上。任何帮助将不胜感激。
答案 0 :(得分:1)
错误是我忘记在我的一个字符串的末尾添加\ n。因此,该程序挂起了对inFlo.readline()的调用。