N
N
nnikolyaa2021-05-22 15:55:21
JavaScript
nnikolyaa, 2021-05-22 15:55:21

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


Server
incoming_data_str = str(connection.recv(1024).decode('utf8'))


I tried to make through
incoming_data_str = ''
while True:
  incoming_data_str += str(connection.recv(1024).decode('utf8'))
  if not incoming_data_str: break

but he was silent.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-12-18
@NikitosAndreevich

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.

N
nnikolyaa, 2021-05-22
@nnikolyaa

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)

client part
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 question

Ask a Question

731 491 924 answers to any question