我需要写一个服务器和一个cliet做4件事
1.发送收到消息的时间
2.把所有的文件放在一个文件夹里
3.从该文件夹复制一个文件,并在另一个文件夹中创建一个新文件(txt)
4关闭程序
克林特:import socket
import os
import pickle
s=socket.socket()
addr=('127.0.0.1',8200)
s.connect(addr)
choice="0"
while choice!="4":
print s.recv(4068)
choice=raw_input("please choose a service number:")
s.send(choice)
if choice=="3":
fileName=raw_input("please enter the name of the file you want to download:")
s.send(fileName)
data2= s.recv(4068)
if choice=="1":
print data2
elif choice=="2":
data_arr=pickle.loads(data2)
print data_arr
elif choice=="3":
text=s.recv(4068)
if text=="no file with this name":
print text
else:
newFile=open("newFile.txt","w")
newFile.write(text)
newFile.close()
print "thanks for using our conection"
s.close()
服务器:
^{pr2}$
问题是我在另一台电脑上试过了,但是progrem没有发送消息(粗体),我不明白为什么因为代码在另一台电脑上工作,经过几次测试我知道它找到了文件,一切正常,它只是不发送消息(txt文件不是空的)