How can I make a server and client together with different sockets open?
posted 16 years ago
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 Chris