Answer the question
In order to leave comments, you need to log in
How to send over data sockets more than 1024?
I have a text >1024b in size.
I want to send it over sockets, but the problem is that it is cut off exactly at 1024.
I tried to find a way to fix this, and came across a bunch of options. Did not work out.
Sockets did not receive, but did not send anything. How to fix?
Customer
command_output = "{'command':'"+command+"','user':'"+nick+"','token':'"+token.decode('utf8')+"'}"
connection.send(command_output.encode("utf8"))
command_answear = connection.recv(1024)
print(command_answear.decode('utf8'))
incoming_data_str = str(connection.recv(1024).decode('utf8'))
incoming_data_str = ''
while True:
incoming_data_str += str(connection.recv(1024).decode('utf8'))
if not incoming_data_str: break
Answer the question
In order to leave comments, you need to log in
Returns. Only you don't do anything with it.
And the quotes in the getSentence function are not what you need - they should be reversed.
In short, the problem was that no information was sent at the end to if not data
. I solved it by simply adding the text "END$OF$TEXT" to the end of the message and checking it on arrival if "END$OF$TEXT" in data: break
Server part
def tell(text):
text += " END$OF$TEXT"
connection.send(text.encode('utf8'))
text = "Super mega huge text!"
tell(text)
command_answear = ''
while True:
command_answear += connection.recv(1024).decode("utf8")
if "END$OF$TEXT" in command_answear:
break
print(command_answear[0:-11])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question