【发布时间】:2012-04-01 00:11:46
【问题描述】:
我正在尝试一次将文件的内容发送到客户端 1 行 以便客户端(用 Objective-C 编写)可以单独处理每一行。 但是客户端的日志显示数据是从服务器发送过来的 全部通过 1 条线,显然太大,所以它切断了中间 由于意外的语法,通过一行导致客户端崩溃。
我在服务器上做的事情(用 python 写的)是 导致线路不单独发送?
这是服务器中目前让我无法工作的特定代码。
def sendLine(self, line):
self.transport.write(line + '\r\n')
def updateShiftList(self):
#open the datesRequested file for the appropriate store and load the dates into a list
fob = open('stores/'+self.storeName+'/requests/datesRequested','r')
DATES_REQUESTED = fob.read()
datesRequested = DATES_REQUESTED.split('\n')
#open each date file that is listed in datesRequested
for date in datesRequested:
if os.path.isfile('stores/'+self.storeName+'/requests/' + date):
fob2 = open('stores/'+self.storeName+'/requests/' + date,'r')
#load the file into memory and split the individual requests up
THE_REQUESTS = fob2.read()
thedaysRequests = THE_REQUESTS.split('\n')
for oneRequest in thedaysRequests:
if len(oneRequest) > 4:
print "*)[*_-b4.New_REQUEST:"+oneRequest
self.sendLine('*)[*_-b4.New_REQUEST:'+oneRequest)
fob2.close()
fob.close()
太令人沮丧了,我相信这很容易。谢谢。
【问题讨论】:
-
感谢 DSM,没有使用 sendline 只是因为我一直在尝试其他方法来查看它是否改变了输出。我更新了代码以反映这一点,并在文件上添加了正确的关闭。谢谢。即使在该方法之前启动的另一个方法中的另一行中,这些行仍在合并在一起。