Why don't ppl use threads for serversockets? They place them in main and any
such places. Are there any drawbacks to this?
listenSocket = new ServerSocket(port);
while(true) {
Socket clientSocket = listenSocket.accept();
etc.
}
Printable View
Why don't ppl use threads for serversockets? They place them in main and any
such places. Are there any drawbacks to this?
listenSocket = new ServerSocket(port);
while(true) {
Socket clientSocket = listenSocket.accept();
etc.
}
I'm not an expert on the subject, but since no one else posted a response
i'll
give it a shot. In one of my CS classes we wrote a proxy server and proxy
thread. In the main we
had something like,
...
serverSocket = new ServerSocket(port_number);
...
and waited for a client to connect to the port. Then When a client connected
we had,
...
clientSocket = serverSocket.accept();
new ProxyThread(clientSocket).start();
...
This started a thread that handled the real work of the proxy.
This means the server can immediately go back to it's job of waiting for
a client to connect to it's port. To answer your question about draw backs,
I would
imagine it is really a question of what you are trying to accomplish and
the best way to
implement that in code. And not so much if it is better to do that in a thread
or in the main.
Hope this helped.
--Dave
"Freddy" <.@.> wrote:
>
>Why don't ppl use threads for serversockets? They place them in main and
any
>such places. Are there any drawbacks to this?
>
>
>
>listenSocket = new ServerSocket(port);
>while(true) {
>Socket clientSocket = listenSocket.accept();
>
>etc.
>}