@solid dune
Blocked Web TLDs
To maintain a wholesome and friendly environment we block all links to websites using certain TLDs. Your message has been deleted.
Detected TLD(s)
xxx
89 messages · Page 1 of 1 (latest)
@solid dune
To maintain a wholesome and friendly environment we block all links to websites using certain TLDs. Your message has been deleted.
Detected TLD(s)
xxx
print function wont execute inside while loop
heres my implementation
import socket
from socket import AF_INET, SOCK_STREAM
import struct
with socket.socket(AF_INET, SOCK_STREAM) as cl_sock:
cl_sock.connect((HOST, PORT))
# getting the name of file
name = cl_sock.recv(1024).decode()
print(f"name received filename: {name}")
# getting the size of file
packed_size = cl_sock.recv(8)
total_buffer_size = struct.unpack("Q", packed_size)[0]
print(f"size received totalsize: {total_buffer_size}")
# bcz dynamic allocation sux:(
bytes_received = bytearray(total_buffer_size)
print(f"getting akshuall file now pls work")
# getting the akshual file
while (x := total_buffer_size) > (y := len(bytes_received)):
print("working...?")
chunk_size = min(4096, total_buffer_size - bytes_received)
chunk = cl_sock.recv(chunk_size)
bytes_received.extend(chunk)
# walrus bcz me lazy + no lsp :/
print(f"almost there {x}/{y}")
# saving file :)
with open(name, "wb") as file:
file.write(bytes_received)
print("script executed successfully")
code works just fine tho
You're looping while total_buffer_size is greater than len(bytes_received) but when you create bytes_received you tell it to fill it with total_buffer_size zeros so its length is always equal to total_buffer_size and so total_buffer_size is never greater than len(bytes_received)
And that was a run on sentence...
bytes_received = bytearray()
while total_buffer_size > len(bytes_received):
print("working...?")
chunk_size = min(4096, total_buffer_size - bytes_received)
chunk = cl_sock.recv(chunk_size)
bytes_received.extend(chunk)
print(f"almost there {total_buffer_size}/{len(bytes_recieved)}")
You need an empty bytes_recieved for your code to work
appreciate it
Also no need for assignment expressions in your while condition
yeah i was just coding without anything...
never done that
like without even a type checker or lsp
i mean len(bytes_received) would be used thrice so why is walrus a bad idea here?
while total_buffer_size > len(bytes_received):
print("working...?")
chunk_size = min(4096, total_buffer_size - len(bytes_received))
chunk = cl_sock.recv(chunk_size)
bytes_received.extend(chunk)
print(f"almost there {total_buffer_size}/{len(bytes_recieved)}")
_ _
ik it isnt much but i was coding without a code editor......
also i thought not doing dynamic allocation would be an option for me since i already know the file size :/
The first and second time it's the initial value, the third time its a new value. So if you assign it to y it'll be wrong in the third use
So if you assign it anywhere, assign it in the third use
ooo yesss it gets evaluated from there
bytes_received = bytearray()
y = 0
while total_buffer_size > y:
print("working...?")
chunk_size = min(4096, total_buffer_size - y)
chunk = cl_sock.recv(chunk_size)
bytes_received.extend(chunk)
y = len(bytes_recieved)
print(f"almost there {total_buffer_size}/{y}")
Might actually be faster to just add chunk_size to y
bytes_received = bytearray()
y = 0
while total_buffer_size > y:
print("working...?")
chunk_size = min(4096, total_buffer_size - y)
chunk = cl_sock.recv(chunk_size)
bytes_received.extend(chunk)
y += chunk_size
print(f"almost there {total_buffer_size}/{y}")
interesting... dont call it y plz
rb_list = bytearray(total_buffer_size)
print(f"getting akshuall file now pls work")
# getting the akshual file
start = 0
while chunk := cl_sock.recv(4096):
rb_list[start : start + len(chunk)] = chunk
start += len(chunk)
print(f"bytes received: {total_buffer_size}/{start}")
btw my whole concept of array is ruined now
its not an array
btw no dynamic memory allocation here :D_ _
tested it with an image and it worked
valid phyton 💀
4 barray = bytearray(9)
3 print(len(barray))
2 barray[0:3] = 2, 2, 2, 8, 90
1
12 print(len(barray))
~
i thought arrays were data structures of fixed len
tbh ive never seen anyone using streams like that recvin till EOF is the only good practice ig?
wouldnt matter in my case since its by size of chunk
bro how is this more efficient
y = 0
while total_buffer_size > y:
chunk = cl_sock.recv(4096)
rb_list.extend(chunk)
y += len(chunk)
print(f"bytes received: {total_buffer_size}/{y}")
this took:
total time taken: 0.008171840978320688
....
while my implementation took:
total time taken: 0.009359975985717028
i mean ive only tested it on an image will try sending the os file through it
More efficient than what specifically?
than this
That's doing a copy
rb_list[start : start + len(chunk)] = chunk
So yeah, slow
Extend drops the existing object into the bytearray while using a slice forces the data to be copied over to fill the existing memory that belongs to the bytearray
been too long since I've done python this all just looks like squiggles to me ngl
It’s literally python. Read it as if it were plain English and it’ll make sense
bro I speak polish, I can understand English perfectly well
but that....naw
that ain't English, tf is an rb_list
why you gotta abbreviate everything and love the underscores
and when I saw "y"as a variable... bro ima cry
I'm going to my corner, this is just too much for me
received_bytes_list:)
list part was ironic cuz its not really an array imo xD
oh yeah a list in python is just a dynamic array right?
wbrb_seq?
list is a type of array yeah otherwise you could do import array
idk I hate static arrays, they made me wanna kill someone
recevied_bytes_sequence
lol
also tf you analysing data for? you making a bomb or smthn?
i used to think like that
I mean you can always work around static arrays, just make a new one and release the old one and whatever
its a file transfer 💀
aha
so i did it real transfer and for the extending one its
0.42...
and for the copy one its
-438962.97..... 💀
what are you even transfering
eh i tested it on an image
aha so uhhhh I assume you just did it cause why not
or you tryna move your hentai stash without anyone looking, I get it been there tok
God if my gf saw me saying that I'd be dead, she's literally right next to me god save me
you got your damn IP in the open like that??
@spice jewel bro you alive...
wait why tf you.got your ip out like that, yknow having it out won't change anything lol
not rob have my public ip i dont want him to know what computer im using
like oh wow some is gonna ddos meeee but wait I can just calllllll my isp and they will c**kblock yoy
I mean most people don't know that you can abuse the ntp servers to send terabytes of data per second, thanks a proper fucking ddos
#💬general