簡體   English   中英

從客戶端向服務器Python發送字符串消息

[英]Sending string message from client to server Python

我將這些發送行添加到客戶端和服務器的recv行后,就無法運行我的代碼。 我不知道怎么了 沒有它們,該程序將完美運行。 為了方便調試,我只粘貼了盡可能小的代碼,因為沒有這些行,代碼就很完美。

客戶端

    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")

Server.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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM