aspose file tools*
The moose likes Java in General and the fly likes Stop server on localhost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Stop server on localhost" Watch "Stop server on localhost" New topic
Author

Stop server on localhost

Vicky Thakor
Greenhorn

Joined: Sep 04, 2010
Posts: 19

here code working fine. But whenever i tried to stop the server it shows the error

"Could not run Server on port 4444"

-i used stop,destroy,and suspend on thread.

and thread is still running. how can i stop this server by other class???



Thanks

[edited to add code tags]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30768
    
156

Vicky,
Welcome to JavaRanch!

We have different forums here by topic. This doesn't appear to be JDBC related so I'm moving to Java in General. I also added code tags to make it easier to read.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I believe you're using the wrong approach because you're re-creating serversockets.
Shouldn't it be something like this:



// Edit: And welcome to the JavaRanch


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi Vicki,

The nicest way to stop your server would be to have a special command that means "stop the server", then write a tiny program which just sends that command to the server. For some servers, that command can come over the same ServerSocket used to talk to clients; for others, it could be designed to use a second ServerSocket, listening on a different port, to receive that special command. Either way, the command can jsut call System.exit() to stop the JVM.


[Jess in Action][AskingGoodQuestions]
Vicky Thakor
Greenhorn

Joined: Sep 04, 2010
Posts: 19
Wouter Oet wrote:I believe you're using the wrong approach because you're re-creating serversockets.
Shouldn't it be something like this:



// Edit: And welcome to the JavaRanch



In while loop serverRunning is boolean but server object doesn't relate any thing to boolean. Is it possible to change in my code that works fine.

Like start server by other program and stop server by other program.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Working code and correct code are to completely different things. I would encourage you to read this tutorial from Oracle about sockets. Especially the "Writing the Server Side of a Socket" part. Try to build a multi-threaded server and don't forget to synchronize/lock the serverRunning boolean when starting and stopping the server.
Vicky Thakor
Greenhorn

Joined: Sep 04, 2010
Posts: 19
Wouter Oet wrote:Working code and correct code are to completely different things. I would encourage you to read this tutorial from Oracle about sockets. Especially the "Writing the Server Side of a Socket" part. Try to build a multi-threaded server and don't forget to synchronize/lock the serverRunning boolean when starting and stopping the server.


thnks i'll back to you soon with the result....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Stop server on localhost