套接字程序挂起
我正在尝试使用 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() 的调用上。任何帮助将不胜感激。
I'm trying to get some basic networking going in python. Here's the snippet of the program that does the actual communication:
Client Side
# 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()
Server Side
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'
The program seems to be hanging on the call to inFlo.readline() in the client side. Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误是我忘记在字符串之一的末尾添加 \n 。因此,程序挂在对 inFlo.readline() 的调用上。
The error was that I forgot to add a \n at the end of one of my strings. Due to that, the program was hanging on the call to inFlo.readline().