I've been messing around with socket programming lately, and I've realized that there are two possible ways to write a server.
One, with Java, you can say something like
However, I've been using wxWidgets, and I looked at their socket libraries, and they differently. The program doesn't have to sit in a loop and wait for connections. Rather, whenever the server gets any activity on the port it calls a function that you define.Code:SocketServer server = new SocketServer (port); Socket client; while (true) { client = server.accept (); if (client != null) // do something }
This, in my mind, is just like interrupt programming.Code:void classname::OnSocketEvent (wxSocketEvent &event) { // do something }
Which of these two ways is best? Which should I use? What are the advantages and disadvantages?



LinkBack URL
About LinkBacks


