【发布时间】:2018-03-23 09:33:54
【问题描述】:
详情
我正在尝试了解实现选择性重复 (SR) 协议的网络程序。流程如下:
- 通过指定端口号、协议和窗口大小运行 server.py
- 通过指定文件名、端口号和数据包数运行 client.py
当我运行 client.py, 我收到这个错误:
Traceback (most recent call last):
File "client.py", line 238, in <module>
cs = pack('IHH' + str(len(data)), 's', seqNum, header, data)
struct.error: repeat count given without format specifier
这是让我感到困惑的代码块:
while not sendComplete:
toSend = lastInWindow + 1
data = GetMessage()
header = int('0101010101010101', 2)
cs = pack('IHH' + str(len(data)), 's', seqNum, header, data)
checksum = CalculateChecksum(cs)
packet = pack('IHH' + str(len(data)) + 's', seqNum, checksum, header, data)
if toSend < windowSize:
sendBuffer.append(packet)
timeoutTimers.append(TIMEOUT)
else:
sendBuffer[toSend % windowSize] = packet
timeoutTimers[toSend % windowSize] = TIMEOUT
疑难解答
我已经采取了几个步骤来解决这个问题,但都失败了(很明显),我不确定我是更接近光线还是深入树林。
- 按照 PyCharm 的建议使用 struct.pack(fmt=...)
- 根据 PyCharm 的建议,我使用 + 连接参数
- 我再次运行程序并收到 TypeError: must be str, not int 错误,我尝试通过实现 str(seqNum)、str(header) 等来解决此错误。
- 最后,我得到一个 TypeError: pack() takes no keyword arguments 响应并认输。
如果有人能解释这里发生了什么以及如何启动和运行这个程序,我将不胜感激。
【问题讨论】:
标签: python struct network-programming