لدي مشكلة في البرنامج التالي
import socket, sys
port = 70 #Gopher user port 70
host = sys.argv[1]
filename = sys.argv[2]
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
s.sendall(filename + "\r\n")
while 1:
buf = s.recv(2048)
if not len(buf):
break
sys.stdout.write(buf)المثال مأخوذ من كتاب Foundations of Python Network Programming وهو عبارة عن Simple Gopher Client عندما حاولت ان اقوم بتنفيذ المثال طبعاً بعد حفظه بأسم gopherclient.py لم استطع وكانت تظهر لي رسالة الخطاء التالية
Traceback (most recent call last):
File "C:\Users\WVHPA\Desktop\PIN\gopherclient.py", line 4, in <module>
host = sys.argv[1]
IndexError: list index out of rangeالسؤال الاول : كيف يمكن حل مشكلة هذا الخطاء
السؤال الثاني : هل من احد الاخوة ان يشرح اكواد البرناج لأنه لا يوجد في الكتاب سوى الية عمل البرنامج والحمد لله هذي بسيطة وواضحة وقد وضعتها في النص التالي لمن يريد ان يطلع عليها
اقتباسThis program takes two command-line arguments: a hostname and a filename,
and requests the appropriate document from the host.
It creates a socket with the call to socket.socket().
The arguments tell the system thar it wants an internet socket for stream (TCP) communication.
then the program connects to the remote host and transmits
the filename.Finally,it reads back the response and print it to the screen
واعتذر عن الاطالة في الحديث
وجزاكم الله كل خير