나는 여전히 학생이기 때문에 나는 정말 명백한 것을 놓쳤을지도 모른다.내 사소한 tftp 클라이언트 뒤에 결함이 논리입니까?
그래서 나는 이것에 대해 아주 많이 강조하고 있습니다.
어쨌든 여기 내 TFTP 파이썬 코드가 있습니다. 강사 서버에서 텍스트 파일을 다운로드하는 것입니다.
그것에 의해 생성 된 파일은 다음과 같습니다 : http://pastebin.com/TP8hngxM
그리고이 같은 원본 파일 : http://pastebin.com/xDMjkABp
그리고 당신은 차이 검사기를 통해 실행하는 경우, 그 차이가 미미 만 1입니다 특정 장소에 도착했는데 왜 이런 일이 발생하는지 파악하기가 어렵습니다.
다운로드 한 파일에는 몇 가지 추가 단어가 있습니다.
예비 5 분이 있다면 중첩 된 while 루프를 확인해 주실 수 있습니까? (다른 모든 것은 강사가 제공 했으므로 변경할 수 없습니다) 문제가 있는지 확인하십시오.
최악의 경우는 이미 작동 했었지만 메모리 스틱을 잃어 버렸고 100 % 정상적으로 작동하는 프로그램의 최신 버전을 잃어 버렸습니다.
그래서 내가 말했듯이 중첩 된 while 루프 일 뿐이므로 위에있는 것을 변경할 수는 없습니다.
#!/usr/bin/python
import struct
import sys
import os
import select
import glamnetsim
from socket import *
serverHost = 'mcgreg.comp.glam.ac.uk'
serverPort = 69
timeoutSecs = 5
debugging = False
RRQ, WRQ, DATA, ACK, ERROR = range(1, 6)
codeDescriptions = {RRQ:"RRQ", WRQ:"WRQ", DATA:"DATA", ACK:"ACK", ERROR:"ERROR"}
def printf (format, *args):
print str(format) % args,
def finish():
printf("you should see\n1e951df315d433aa4df2065a1ad31311\n")
os.system("md5sum newfile.txt")
sys.exit(0)
def sendPacket (packet, port):
global sock, debugging
global serverIp
if debugging:
for i in packet:
print ('%02x' % ord(i)),
print ''
sock.sendto(packet, (serverIp, port))
def sendReadRequest (filename, mode):
global serverPort
format = "!H%ds" % (len(filename)+1)
format += "%ds" % (len(mode)+1)
s = struct.pack(format, 1, filename, mode)
sendPacket(s, serverPort)
def sendRealAck(blockno, port):
s = struct.pack("!H", 4)
s += struct.pack("!H", blockno)
sendPacket(s, port)
def sendACK (blockno, port):
print " -> ACK:%d\n" % blockno
if blockno == 0:
sendReadRequest("the_machine_stops.txt", "octet")
else:
sendRealAck(blockno, port)
def stripPacket (s):
if len(s)>3:
code = struct.unpack("!H", s[:2])[0]
blockno = struct.unpack("!H", s[2:4])[0]
data = s[4:]
code, data = glamnetsim.simulatePossibleError (code, data)
return code,blockno,data
else:
debugPrint("corrupt packet")
return -1,-1,""
def debugPrint (s):
global debugging
if debugging:
print s
def getDesc (c):
global codeDescriptions
return codeDescriptions[c]
sock = socket(AF_INET, SOCK_DGRAM)
serverIp = gethostbyname(serverHost)
sock.setblocking(1)
sendReadRequest("the_machine_stops.txt", "netascii")
lastblock = 0
blockno = 0
port = serverPort
f = open("newfile.txt", "w")
while True:
while True:
if blockno == lastblock+1:
break
r, w, x = select.select([sock], [], [], 5.0)
if r == []:
sendACK(lastblock, port)
else:
(packet, (address, port)) = sock.recvfrom(512+4)
code, newblock, text = stripPacket(packet)
print code, blockno
if code is 3:
blockno = newblock
sendACK(blockno, port)
if code is 5:
sendACK(lastblock, port)
print "Bn: " + str(blockno) + " Lb: " + str(lastblock)
lastblock = blockno
f.write(text)
print "OK"
if len(text) < 512:
break
f.close()
finish()
나는 이것을 알아 내려고하고 있는데, "if code is 5 :"가 발생했을 때 휴식해야한다고 생각합니다. 너희들은 어떻게 생각하니? –
나는 이것을 재현 할 수 없다고 생각한다. 'glamnetsim'이란 무엇입니까? – nickie
그것은 대학에서 우리의 내부 네트워크를 시뮬레이트하는 기능입니다. 방화벽 뒤에 있으므로 내 코드를 실행할 수 없으므로 연결하려면 캠퍼스에 있어야합니다. 나는 프로그램 자체의 논리에 문제가 있는지 알아 내려고하고있다. –