Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I make a server and client together with different sockets open?  RSS feed

Chris Ben
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a question about socket programming on server and client. I want to write a server which has one server socket always open to listen to some information. At the same time, the server will automatically send messages to many clients whenever some events happen.
I know this is a common way for a server working on-line, but when I implement it in a java program by myself, I found I got some problems in design. Because whenever I call serversocket.accept() it will block the IO and further work untill it get connected, how can I keep it listening for any connections and let it send messages whenever some other events happen? In this case, this program will be a server for some machines and a client for other machines. I feel threading may be the answer but I hope I can get more ideas about how.
Thanks a lot
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!