This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes socket and servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "socket and servlet." Watch "socket and servlet." New topic
Author

socket and servlet.

Ruslan Ivanov
Ranch Hand

Joined: Feb 22, 2001
Posts: 72
I am using servlets in my current development. Now i am confused about how they work a bit. I understand that unless i implement a SingleThreaded interface the servlet by default is multithreaded right ? Now let's say that in one of my servlets doGet method i open a connection to a socket. Now i can keep that connection open for a long time , so to prevent my doGet from finishing i placed a syncrhonized block in there and a wait method to wait until certain task is complete my syncrhonized block is on this meaning on current servlet object. Now when the thread finishes it it notifies that its free to exit the doGet method. It works fine andn i get no problems. Problem i think is that when i try to open another Client browser and connect to my servlet i get connected but the first browser stops recieving input from the Socket. I dont see anywhere that the thread has exited it just no longer recieves the output from the Socket. What can be wrong with it ? I am testing this on one machine. Both clients on one machine and the ServerSocket again is also opened on this machine. Could it be the problem with that ? I see that the messages go to all the clients from the output in debug , but just only the last one recieves it. Thanks for your assistance.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5

Are you catching and reporting any exceptions that occur in your socket code?
Bill
Ruslan Ivanov
Ranch Hand

Joined: Feb 22, 2001
Posts: 72
There are no exceptions at all , as far as i know that it works fine it's just that the first browser where the user is waiting for messages stops recieving them . I have println everywhere to see if he has existed doGet method where he has to recieve messages and he hasn't yet exited , so that can't be the problem. I just don't know what is anymore.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: socket and servlet.