• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Images transfer through socket

 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I tried to send multiple images through a socket. I have given the code and exceptions below. Either a single or two images is transferred properly when it comes to third image, it shows the following error

Server code:



Client Code:


Server Exception:



Client Exception:


 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:
Server Exception:




Your debugging messages and stack trace does give you a starting place to look. For some reason, it messes up the reading of the file and detects that it is looking for a file name "34775" with a file size of "GIF89aV". This is clearly wrong, and fails later when you try to do the parseInt() which expects a number. I would recommend looking to see how the applications gets out of sync.

Henry
 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:
Client Exception:




This is just saying that the socket write failed because the other side of the connection unexpectedly disconnected -- which is what automatically happens when the JVM terminates. And of course, your server JVM terminated because of the exception.

Henry
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

Thanks for the reply. I know the meaning of stack trace and I am trying to figure it for the past two days but I can't. That's why I posted here for advice from experts like you
 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:Henry,

Thanks for the reply. I know the meaning of stack trace and I am trying to figure it for the past two days but I can't. That's why I posted here for advice from experts like you


Well, it would help us if you tell us what have you been doing for the last two days. Have you been debugging the communication to see what commands are sent? Have you been looking to see if some extra (or less data) are sent to get the commands out of sync? Tell us what you tried, and perhaps we can guide you.

Henry
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

I tried running a single image and then two images. Both worked but when I give a third image in the source folder, it gives this exception. I tried printing every value I pass. I changed the buffer size. I converted image in server side as a bufferedimage[] and tried writing the image in a file as a single thread. I tried sending ack's between the client and server after every transaction. Nothing worked same output.
 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:
I tried running a single image and then two images. Both worked but when I give a third image in the source folder, it gives this exception. I tried printing every value I pass. I changed the buffer size. I converted image in server side as a bufferedimage[] and tried writing the image in a file as a single thread. I tried sending ack's between the client and server after every transaction. Nothing worked same output.


First, I would recommend checking to see if it is always the third image or always that image. If the first, you need to see what happens during an image transition. If the second, you need to see what is so special about the file.

Regardless, I would recommend you work backwards from the failure. You know the exact reason why it fails, you just need to figure out why the commands go out of sync -- start adding debugging messages from the failure point backwards towards the root cause. Stuff like converting the image and "sending acks" are attempts at fixes, and without knowing the root cause, these "fixes" are just blind code changes.

Henry
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

Its not always the third file at times, this occurs for the second file too. It varies from run to run.

I will try working backwards now and the debugging messages you are suggesting me, may I know what that is? I don't have any idea on what that is
 
Henry Wong
author
Sheriff
Posts: 22541
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Partheban Udayakumar wrote:
Its not always the third file at times, this occurs for the second file too. It varies from run to run.

I will try working backwards now and the debugging messages you are suggesting me, may I know what that is? I don't have any idea on what that is


Well, you are somewhat lucky here... the error is occurring pretty early. Imagine if it occurs on the thousandth or millionth iteration -- then adding a single debugging line can greatly increase your log file. With it occurring on the second or third iteration, you pretty much add tons of debugging messages, and your output won't be unwieldy.

There is no black magic with debugging messages. You simply need to print out what you are getting to confirm that it is correct or incorrect. And if it is incorrect, then you need to go backwards in code to find the point where it becomes incorrect -- which of course, means that you need to do another run. And if the cause is some other data being incorrect, then you need to go backwards on that as well. The hardest part in your debugging is that you will need to cross the network to another JVM, so that may be a bit hard to follow. For that, I would recommend putting a time stamp, then you have some idea of what occur in what order. There will be some time synchronization issues -- as clocks are not always in sync between applications, but that can't be helped.

Good Luck,
Henry
 
Domi Dori
Greenhorn
Posts: 6
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the last iteration of your read loop when you read the image from the stream.

How many bytes should it read? How many bytes does it read in the worstcase?
 
Partheban Udayakumar
Ranch Hand
Posts: 496
AngularJS Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Domi Dori,

I did as you said and the actual bytes to be read is 34765 but it reads 34789. But when i print the parameters in while loop, it stops before it at 33729 but the final bytes read comes out as 34789.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!