You are by far my favorite source for Python lessons. 1. You have a solid intro. 2. Your videos are not too long. 3. Even though the videos are not that long, you are clear on your explanation. Thank you for doing this.
@BatteryProductions6 ай бұрын
you are using file_size only to print the size, you could also use that information to do the loop instead of a tag, just read data until data == file_size...
@lastdance20992 жыл бұрын
I'm seeing verbatim copies of this code being used all over the place and it has to stop. This code is filled with unreliable constructs. It exhibits every python sockets' bad practice I've seen in the last 10+ years. 1) If you don't check the return value from send() that's a bug. You should be using sendall() for all the sends that you're not checking the return value of, which in this case is all of them. 2) Although perhaps not a big deal for this particular example, assuming that a fixed chunk of bytes like 1024 will end on a utf-8-encoded unicode character boundary is incorrect; 3) The biggest mistake is your assumption the every single send() or sendall() will be read by a single recv on the server side. That's not how tcp works and not how python SOCK_STREAM sockets work. If you send 1022 bytes in one send and 25 bytes in the next send, then on the server side you may receive 50 bytes in your first recv(1024) and then 100 bytes on you next recv(1024). Or you might receive 1024 bytes in your first recv(1024) but then only 1 byte in your next recv(1024). In your case, you might receive the file name, the file size, and a big chunk of the file itself in your first recv(1024) that you're assigning to the variable file_name. See the following answer on stack overflow for more details: stackoverflow.com/questions/43420075/python-socket-not-receiving-without-sending/43420503#43420503.
@bruhhhhh718 Жыл бұрын
thanks for this knowledge
@FlexThoseMuscles19 күн бұрын
Thanks a lot, this solved the particular problem I was encountering on my computer.
@adventinfomax69032 жыл бұрын
You've actually got so quality stuff on your channel. Keep that up man!
@gonzalogoded20898 ай бұрын
I tried sending a 800Mb file and noticed it kept going slower and slower and eventually would take hours to pass, the reason being the internal fixed length of byte type variables and had to replicate all file every interaction. Found the solution. Substitute the line file_bytes = b"" for this one: file_bytes = bytearray(), from hours to transfer went to 8 seconds
@klausvonshnytke2 жыл бұрын
Just wondering, don't you end up with the string appended to the transferred file?
@andme-tech102 Жыл бұрын
I don't think so because the file data and string were sent as two separate transmissions so in the receiving end in receives file data first before the END string so when it reaches the end string it terminates writing to the file without actually including the END string
@klausvonshnytke Жыл бұрын
@@andme-tech102 I tested this code and does get appended at the end.
@elimelechschreiber6937 Жыл бұрын
Yes of course. This is an obvious bug. The filesize would be larger, and a checksum test would obviously fail. Although an image and even simple executables should still work.
@scorpio38992 жыл бұрын
Great stuff, I'm working with a project using sockets and this might help me. And btw you can also send Python objects using the library pickle, this works if you need to send an array of data or some complex object you're working with
@donatellosnizzo1002 жыл бұрын
saving an object in a file with pickle and then sending that file. nice one!!
@scorpio38992 жыл бұрын
@@donatellosnizzo100 well it doesn't create a file, it just wraps an object and just send it, it helps when you don't wanna save too many files of images, objects or whatever you wanna send, so you can pass multiple array of data or anything else without wasting hard-drive space
@bruhhhhh718 Жыл бұрын
i think it's important to note why you are using os.path.getsize vs file.__sizeof__ -- one is size on disk, the other size in memory
@davidtindell950 Жыл бұрын
Thank you! I do like your inclusion of the progress bar!!
@lawrencedoliveiro91042 жыл бұрын
Have you looked at passing open file descriptors over Unix-domain sockets? So for example an authentication process could control access to a particular directory, and grant selected client processes permissions to read/write files there. And all of this could be done without anybody needing root privileges.
@businessdissection1302 жыл бұрын
Honestly, I started watching your videos for the intro music. And stayed for the content.
@yunisguliyev381510 ай бұрын
i am 70% sure that he recorded this video after break up. got the vibes
@ghost99slay2 жыл бұрын
Yo! Congrats on the 150k homie! Keep up the good work!! I love watching your videos
@trido38152 ай бұрын
Great info. Thanks. BTW, for the sender, I think we can use the context manager at 'open' . Right?
@minhajhossain337 Жыл бұрын
I love your videos Florian. Because, you always explain everything very easily in a short time period 😊😊😊
@tommyhuffman7499 Жыл бұрын
Your channel is underrated
@ethanberg19 ай бұрын
Thank you! You just made my life easier next week!
@olorundaremicheal80152 жыл бұрын
Thanks for this boss. I have been hoping to understand this for a long time. Please could you do a tutorial on how to connect to a remote cloud database with python. Thanks.
@thepoorsultan51122 жыл бұрын
MySQL database?
@felloforest Жыл бұрын
very informative. Not too brief but you get the concepts behind it.
@shentrax Жыл бұрын
Curious - did you not have to strip the off the received file before writing the last bit of data?
@MekeninzoUG7 ай бұрын
Of course not. As soon as the tag is detected, the loop ends and nothing gets added to file_bytes down the detection line, so nothing to remove.
@BatteryProductions6 ай бұрын
@@MekeninzoUG but he explained that maybe so he checks last 5 bytes ALREADY appended to file.. this is a bug...
@MekeninzoUG6 ай бұрын
@@BatteryProductions Yeah I never thought of that, but now I'm so far beyond this level. Using tags is a terrible practice. Much better to put a header on your data packets.
@51swarajrohad87 Жыл бұрын
bro there's a loop hole when a byte is received with ending as and saved in data it'll check file_bytes which will be false and else part will execute and the end will be appended in file_byte then theres no data to receive right so it should end there but it's not and loop iterates again and client.recv tries to recieve data which the sender has already finished sending. so it will be stuck there forever . Please correct me if i'm wrong
@BatteryProductions6 ай бұрын
yes, avoid appending to anything, use file size instead compare to data size
@Herzfeld10 Жыл бұрын
please use a context manager when handling files (keyword "with")
@ΠΑΝΟΣΚΩΣΤΟΠΟΥΛΟΣ-η3χ4 ай бұрын
really nice video just a mistake i see. when dealing with large files/data you cant have a variable to include all the data. that is why we have buffers generally for memory purposes. when reading a chunk of the file this chunk should be either passed to another socket or saved in disk not RAM. In C when reading from a socket the number of characters being read is returned so you know when the file is done, and also the eof is 1 byte aka one character. dont know exactly why in this it is not familiar with how python handles files
@oguzhantopaloglu94422 жыл бұрын
Congratz on 153k subs, I have been following you for a while now your videos are pretty good! Could you maybe make more videos about Java? Maybe Java networking or something like that using Spring?
@alexdelarge1845 Жыл бұрын
i second this sugestion. it would be awesome some java sockets tutorilas
@abdultheseekerofknowledge4453 Жыл бұрын
Who uses Java on this day and age, maybe try something like Node.js, GO, Rust
@oguzhantopaloglu9442 Жыл бұрын
@@abdultheseekerofknowledge4453 Those words of your are too bold for an argument that can be destroyed with a simple linkedin search lmao Java probably has more job offers than all those 3 combined xD
@abdultheseekerofknowledge4453 Жыл бұрын
@@oguzhantopaloglu9442 I think we should get real, Java is becoming like Php, in android app development Kotlin is far ahead of Java, for a backend development GO and Rust are far better options
@oguzhantopaloglu9442 Жыл бұрын
@@abdultheseekerofknowledge4453 "for a backend development GO and Rust" YEAH YOU WISH 💀💀💀💀💀
@jansz1589 Жыл бұрын
I have one little problem... When I send few back to back messages I end up with one big message that is essentially just all the messages concatenated. I don't know how to solve it and I see you somehow managed to do that. So my question is: how?
@FramesByAkhil8 ай бұрын
What if recived bytes contains end delimiter and next file name , if continuous files are transmitted
@LHM1226 Жыл бұрын
What library would you recommend for FTP transfer? Would the socket best work with FTP?
@FunueLian Жыл бұрын
Does the image have to be in the same file directory?
@meraklmuskulpesent83132 жыл бұрын
Thanks for the tutorial. For some reason, my code (receiver.py) throws this error: file_size = client.recv(1024).decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 6: invalid start byte Could anyone tell me how to solve this?
@lilahmin2 жыл бұрын
i have the same problem
@alifurqan13752 жыл бұрын
Code runs fine when I run both scripts(server.py and client.py) on the same windows laptop. But when I run client.py on Raspberry Pi (linux OS) and server.py on laptop (windows OS) connected in LAN, I get the following error message :( UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 5: invalid start byte
@lastdance20992 жыл бұрын
The is not a good video, most of the code shown is buggy and should not be emulated.
@edy1219 Жыл бұрын
It's because this isn't a good tutorial, it's literally trash.
@jansz1589 Жыл бұрын
Your reciever recieves file data on top of the file size in one message. That is because of the way the TCP sockets work. If you send multiple messages one after another, there is high chance you will recieve them concatenated, assuming that your connection is not slow. So you essentially try to decode the file with utf-8 which obviously doesn't work.
@MohammadRezaee-wh7zk Жыл бұрын
Hi, Did you make your website server side by python?
@ghostandry878911 ай бұрын
How can i recive the image name? Same as but with ?
@geraldmaina6137 Жыл бұрын
hi can py socket send malware through a phone /pc after getting a wifi ip addres through nmap and a wifi password thrugh netsh wlan in python
@filippocaregnato4098 Жыл бұрын
Does it work with surface? Like cv2 img?
@RitikRaj-we2sc Жыл бұрын
What if we want to send multiple files at the same time. How can we do that in parallel ? Please help me out here 🙏
@ericesquivel5298 Жыл бұрын
Probably use threads
@RitikRaj-we2sc Жыл бұрын
@@ericesquivel5298 even if I use thread to send multiple file, still how will the receiver know which file is coming , how will it differentiate the incoming data
@sksahil43744 ай бұрын
Nice approach
@sayan763 Жыл бұрын
Just had one question if anybody could answer. This method only works over local host or can work over the wifi/internet as well?
@johnthompson4011 Жыл бұрын
On localhost
@sayan763 Жыл бұрын
@@johnthompson4011 Any idea where I can learn to send files over the internet using Socket programming?? Or is it straight not possible. I want to learn it for my project. But my program is giving bind failure while using the global IP address.
@nkehbebey9182 Жыл бұрын
Can this file be sent and received in any format
@EntrepreneurChips Жыл бұрын
Thank You NeuralNine🥰
@omarelesnawy1833 Жыл бұрын
Thank you, nice explanation
@virendrakumar-ez2ue Жыл бұрын
This would not work if the sender and receiver are not on the same system and why are you writing in the image file? You should be omitting this while writing
@abdullahyousef35962 жыл бұрын
How can we make it so we can access this socket through the internet for free instead of just local networks?
@MariamAbouzaid--8 ай бұрын
how to send folder of images?
@tejasnikumbh7764 ай бұрын
how to create file trafer website file tranfer website to mobile (pc to mobile vs mobile to pc)
@juozas1632 жыл бұрын
Thank you so much! It work!
@johnydoe6338 Жыл бұрын
now, how to secure it ?
@sanymiran38452 жыл бұрын
how to do the same on different network? you know what i mean
@majonezowy4522 Жыл бұрын
port forawding
@Roman.Pavelka2 жыл бұрын
Nice! Would not get into the saved file? Seems it works though :)
@edwardlynch-milner89022 жыл бұрын
I'm wondering the same thing
@klausvonshnytke2 жыл бұрын
Also noticed that. Looks like it does get appended but somehow it didn't break the exe
@klausvonshnytke2 жыл бұрын
just recreated this and indeed "" does get appended. This program needs file_bytes = file_bytes[:-5] before writing the file
@ashleybishton742 Жыл бұрын
Great video
@QuransGems-zd1jd5 ай бұрын
man where is the data we sent being stored? Can anybody access that data?
@pablogiri8126 ай бұрын
Muchas gracias!!!!!!
@gassort008 Жыл бұрын
someone can helpme? file_size=client.recv(1024).decode() UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 6: invalid start byte
@edy1219 Жыл бұрын
Sorry mate you got tricked, this isn't a good tutorial the code here is really buggy, find another tutorial.
@mehdismaeili37432 жыл бұрын
Excellent.
@ozkaninonlu28982 жыл бұрын
Awesome
@yashindane28442 жыл бұрын
How to do the same in flask webapp?
@metantonio2 жыл бұрын
def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @app.route('/upload', methods=['POST']) def upload_file(): if request.method == 'POST': # check if the post request has the file part if 'file' not in request.files: return jsonify({"Msj": "No file"}) file = request.files['file'] # If the user does not select a file, the browser submits an # empty file without a filename. if file.filename == '': return jsonify({"Msj": "No selected file"}) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return jsonify({"Msj": "Archivo subido correctamente"})
@arrozyadifalaqi92922 жыл бұрын
I could fix tNice tutorials?
@119nidunkrishna33 ай бұрын
i was like when seeing transfered.exe 🤫😵
@ahmedgamberli22502 жыл бұрын
13. Comment
@philtoa3342 жыл бұрын
Thx_.
@daeskk6 ай бұрын
unreliable and bad code.
@TeriqueCarnegie5 ай бұрын
If possible can u point out what needs to be improved??
@raven-vr5yz5 ай бұрын
bro are you buying positive comments? i have never read such a crap
@grgregrrgsgff18782 жыл бұрын
Hello, I am talking to neuralnine owner. Please response me
@ga8r02 жыл бұрын
Hello, what you need?
@grgregrrgsgff18782 жыл бұрын
@@ga8r0 I need to create a software like Netsupport school, Can you help me for that? Please
@ga8r02 жыл бұрын
@@grgregrrgsgff1878 Sorry, this is out of my area of expertise