-
ServerSocket question
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.
}
-
Re: ServerSocket question
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.
>}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks