【问题标题】:Sending string message from client to server Python将字符串消息从客户端发送到服务器 Python
【发布时间】:2016-09-11 08:32:47
【问题描述】:

一旦我在客户端添加这些发送行并在服务器中添加接收行,我就无法运行我的代码。我不知道怎么了。没有它们,程序运行完美。为了便于调试,我只粘贴了尽可能小的代码,因为没有这些行,代码就完美了。

客户端.py

    print ('Opening file for editting.....')
with open('C:\\Users\\dell\\Desktop\\received_file.txt', 'ab') as e:
    e.write('Ya Allah tera shukar')
e.close()
print ('Editting Done!!!')
s.send("Trial Message")
s.close()
print ("Connection closed")

服务器.py

while (l): #Keep sending it until EOF id found
    conn.send(l) #Keep sending the opened file
    print(repr(l)) #repr(1) gives the string representation of contents of the file. The repr() of a string adds string quotes and backslashes:
    l = f.read(1024) #Keep reading the opened file so the contents appear on the server too
f.close()
print('Done sending the file')
print conn.recv(1024) #This is not receiving the trial message sent by client
conn.send('Thank you for connecting')
conn.close()

【问题讨论】:

  • 你是如何在client.py中定义“s”的?
  • 我怀疑您正在尝试使用字符串作为字节接受方法的参数。
  • 有什么问题?
  • 不,我错误地附加了错误的代码。检查这个编辑过的。当我写 s.send("any message") 时,在客户端。如何在服务器端接收并显示它。我试图基本上将文件的链接从客户端发送到服务器。通过 conn.recv(1024) 行接收它会导致我的程序卡住:(
  • 如果您能指导我完成 c&s 之间的这个发送和接收程序,我将不胜感激。我想将文件的完整路径发送到服务器。

标签: python sockets send file-transfer recv


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2013-04-01
  • 2017-09-15
  • 1970-01-01
  • 1970-01-01
  • 2018-03-02
  • 2017-01-12
  • 1970-01-01
相关资源
最近更新 更多