As ne555 suggested, I wouldn't start with a full image. Start with small words and then try paragraphs worth of plain text, to make sure all that is being received properly.
This is just a guess, but doesn't Python require file.close() to make sure the data is flushed?
as I mentioned, everything is working fine when it comes to communication between server and client.
I sent messages from one side to another, and they are all received and displayed.
The only problems I have left are the ones I mentioned.
I now repeat:
a full image works, if I don't send the size before the image, or sending the size as an integer works too
but then the image generated is faulty.
no worries,
however, with this being said, I now wanted to ask how should I send multiple images from a folder via socket ?
As explained, if I send one without sending the size beforehand, I succeed.
But I am not sure how to send a bunch of them from a folder.
Any hints ?
Basically, work out what's going wrong such that you can only send one thing, and fix that. Then you can send as many as you like.
This might require you having to send some test data. For example, what happens if you send the number 1, and then the number 2? Does the second number arrive? What value do you read? Can you identify from that simple value what is going wrong?
If you open the jpeg image received with a hex editor, what's in it? Can you see the jpeg header information? Does looking at it give you any clue what's going wrong?
@ repeater
As I said before, sending one image is not a problem, but when it comes to send multiple images I get stuck, because I am not sure how to change the line in question.
This is the code that successfully sends one image.
Is there a way to change perhaps the first line in order to send many images ?
As I said before, sending one image is not a problem, but when it comes to send multiple images I get stuck, because I am not sure how to change the line in question.
You said that the second image, the second thing you send, DOES arrive, yes? But there is something wrong with it. What is wrong with it? Is it the right size? If it is the right size, what is wrong with the data?
Try sending two images. Does THIS work? Does THIS send two images? If not, why? What is wrong with the second image?
and the problem that I have, doesn't show after sending more than one image, as I haven't managed yet to do so, but once I include these lines between line 21 and line 23
1 2
long converted_number = htonl(imageDataVec.size());
send(new_socket, &converted_number, sizeof(converted_number), 0);
the picture that the client generates is not a jpeg file but something corrupt, showing the problem that I listed when I first open this thread.
Is it clear now? Or else, ask.
the picture that the client generates is not a jpeg file but something corrupt
But WHAT is wrong with the file? Is it the right size? Is all the data zero? Is the data backwards? WHAT is wrong with the data?
Data is just numbers. What is wrong with the numbers?
If it's difficult to work out what is wrong with all the numbers, what if you just send ONE number. If you just send ONE number, what goes wrong? What number do you receive at the other end.
Yes, yes, I know what you're about to say. You're about to say that when you send a number, it's fine. So send TWO numbers, and if the second number goes wrong, what went wrong with that number?
You can repeat code as many times as you like. The common way to do this is to make it a function:
The thing is that I will eventually have to implement this code to a network camera which will send images one after the other to the client, therefore I would need only one "send" command which will send this stream "live".
Since I don't have access to that camera at home, I am trying with random pictures from a folder for now.
At this point, if you have any suggestion on how should I work at home while lacking such a camera, I will gladly consider your suggestion, if you believe you have a better idea than using pics in a folder.
But WHAT is wrong with the file? Is it the right size? Is all the data zero? Is the data backwards? WHAT is wrong with the data?
Data is just numbers. What is wrong with the numbers?
yet, is still not clear what should I do once I know it.
My code already sends/receives messages successfully,
but again, once I know the content, which I already know, since messages are strings,
what should I do with it?
How is everything you are suggesting related to sending multiple pictures?
All I want to know is how to change my code to make sure that instead of only one image from the same folder, all of the images from the same folder are sent.
All I want to know is how to change my code to make sure that instead of only one image from the same folder, all of the images from the same folder are sent.
You've been told that already. You get a list of the files, and then you call your sending function on each file.
I see the first two bytes there. I was looking for about the first fifty or hundred bytes from the file.
yet, is still not clear what should I do once I know it.
Once you have that additional information, you could post it here.
The aim is to obtain information about exactly what is happening. Then possible remedies can be found. At this stage it still doesn't seem that there is a clear diagnosis of the cause.
That's why I suggested sending a text file. It tends to be easier to spot changes (extra characters or missing characters or changed characters, for example) in a text file.
ROFL, poor ol Repeater, started off 4 or 5 days ago on this with exuberant promise of knowing what to do. Now just a big hole and a witless heap of anger.
I am sorry that you had to repeat yourself.
I should have perhaps been more clear.
I acknowledged the suggestion of writing the function and repeat it for every file, but what I meant was
a way to send all the picture with only one "send" command, instead of a command for each file.
Maybe your way works too, but I am only afraid that on the client side, I would have to write a "recv" command for every file I receive, and I am not supposed to do that.
Do you have a better Idea of what I mean now? Or still confusing ?
long converted_number = htonl(imageDataVec.size());
send(new_socket, &converted_number, sizeof(converted_number), 0);
Do you know what sizeof(long) is on your machine?
Look at Repeater's code in the very next post - the one where the return result of send is checked and retried to make sure the whole data is sent.