Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stop server on localhost

 
Vicky Thakor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 34179
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vicky Thakor
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic