wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes applet loading forever... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "applet loading forever..." Watch "applet loading forever..." New topic
Author

applet loading forever...

sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14


It supposed t be like this..server send image, client display it, based on the image, client gives respond, then based on the client's respond, server send image on n on until the applicatin end.... but when i put "while" it takes forever for the applet to be loaded. it shows java loading image but the program never show up. i was wondering how i can make the program work without having to use "while" which i think makes it takes ages to load...please help me...
Moojid Hamid
Ranch Hand

Joined: Mar 07, 2009
Posts: 120
The code snippet that you provided is not enough to answer your question.

However I think the problem very likely is that the inStream.readLine()is where your code is hanging due to the fact that there is no data to read in the stream. The readLine() is very likely blocking, waiting for data to appear. Like i said before the code is not enough to be certain about that.
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14


this is the whole code...hope you can help...
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14
i need it to be able to display image again and again each time server send a new fileName. And so i put "while" like below. But it takes forever for it to load..

Moojid Hamid
Ranch Hand

Joined: Mar 07, 2009
Posts: 120


What exactly is this socket connecting to?
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14



this is the server code...and it communicate with New(). The thing is, when i run these code, the server is responding perfectly fine with the client. i uses system.out.println to see the outcoming.but unfortunately, the client is unable to display the next image sent by server after the 1st image. to make it work, i put "while" inside the client because i think that is where the problem coming from. but after that, the page takes forever to load..so i figure, i need to use something else other than "while" to make it work....
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Your applet's java console has a trace level of 1-5. Set the trace level to log all messages and check where the trace stops. Perhaps your call to the URL is blocked and is clogging the applet ? Your code was too big to go through so I am taking a hunch


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14
Your applet's java console has a trace level of 1-5. Set the trace level to log all messages and check where the trace stops. Perhaps your call to the URL is blocked and is clogging the applet ? Your code was too big to go through so I am taking a hunch


how to do that?im really new in java...
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

In mozilla firefox - Tools -> Java Console
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14
im using IE and tried that consle thing and it says

Java Plug-in 1.6.0_12
Using JRE version 1.6.0_12 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\ShAr!n
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


Loaded image: http://localhost/strawberry.jpg


this means the client-server connection is wrking. but it just takes forever to load.when i didnt use while, it loads just fine. how come when i started using while it loads forever?all i want is to make the client display the next image given by server... can you please help... do anything.. edit the code or something.. because i tried everything i know but nothing seems to work.. i really need to get this done quickly.. and i have no one else to turn to..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
It may or may not contribute to this problem, but in general it's a bad idea to use readLine and println with sockets: Don't println to a Socket


Ping & DNS - my free Android networking tools app
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14
So what do you suggest? it took me quite a while to figure what suits with what. i thought i have a perfect match. it would be great if you can suggest something for me.
Moojid Hamid
Ranch Hand

Joined: Mar 07, 2009
Posts: 120
So what do you suggest?


1- If you read the article that Ulf suggested you will get the answer to that question.

2- if you look at the code in your threaded server's run method, it is waiting for applet to send it data. Your applet never sends any data to server. Server sends data to applet since it is blocked waiting for data itself. Your applet is blocked since it never receives the data it is waiting for. You need to rethink the logic here.

3- What is the point of while loop? In every iteration it is assigning a new value to image variable, and the old value is discarded without ever being used. From your description of what you are planning to do init method does not seem to be the right place for obtaining next image anyway. Didn’t you mention that the next image is sent based on client’s response? That to me translates into event listener not a while loop.



sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14
i tried...i've took your advices..but i dont know where i did wrong..the program just doesnt work...i've been working on it since then but nothing seems to change...sigh.........
sharin shazizi
Greenhorn

Joined: Mar 23, 2009
Posts: 14

2- if you look at the code in your threaded server's run method, it is waiting for applet to send it data. Your applet never sends any data to server. Server sends data to applet since it is blocked waiting for data itself. Your applet is blocked since it never receives the data it is waiting for. You need to rethink the logic here.


i tried using system.println to see the outcome of this program, it works perfectly fine...no problem at all...meaning the server-client code is fine...but when i try to make it display the image, it just doesnt work...so i assume the problem is with the code of displaying the image in client applet...

can you please explain
the old value is discarded without ever being used


and
From your description of what you are planning to do init method does not seem to be the right place for obtaining next image anyway.


where do you think i should put that init method...and to tell you the truth, i dont even know what exactly this init method is. all i know is i need to put the image in it to display it...its just sad...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: applet loading forever...