> I am looking at pros and cons of two approaches.

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Gordon,
Thanks for your reply.
We have a Server written in C and the guy who is writing the server
insists that he doesn't want to spawn a thread for every request from
us stating that it is inefficient.
>From what i read, this is what a lot of servers do. Please correct me
if the servers follow a different approach.
>From your response,
When a client opens a scoket conn. to the server, the server would use
the same socket to send a response back to that client call. I
understand that the client when it calls the server tells the server to
send a response to a port (which is typically chosen by the client).
and this port is part of the same socket connection that is created. Is
this a correct understanding?
Now in Approach B,
The Server opens up a scoket connection to the client (in effect the
roles are reversed i become the server now). Now i have to look at the
message and tie it up to the client thread that had sent the request to
the server in the first place.
I think this is not a good idea when the server can send the response
in the original scoket created by the client.
Appreciate your thoughts.
Manglu
Mark Haase - 09 Sep 2005 07:25 GMT
> We have a Server written in C and the guy who is writing the server
> insists that he doesn't want to spawn a thread for every request from
> us stating that it is inefficient.
>
> >From what i read, this is what a lot of servers do. Please correct me
> if the servers follow a different approach.
Many servers spawn a new process or thread for each *client* that
contacts it. (Apache Httpd, e.g.)
If he's saying he doesn't want to do this then he's a little silly. A
good threads implementation should be able to handle many threads
without problems. How does he propose handling clients? Sequentially?
Sounds like a bad idea to me, but it has its place and you haven't
explained much about the application and its environment.
|\/| /| |2 |<
mehaase(at)gmail(dot)com
Gordon Beaton - 09 Sep 2005 08:27 GMT
> We have a Server written in C and the guy who is writing the server
> insists that he doesn't want to spawn a thread for every request from
> us stating that it is inefficient.
>
>>From what i read, this is what a lot of servers do. Please correct me
> if the servers follow a different approach.
That is certainly one way, but many servers written in C handle all
clients in a single thread, with select(). The equivalent mechanism in
Java is provided by java.nio.channels.Selector.
>>From your response,
> When a client opens a scoket conn. to the server, the server would use
> the same socket to send a response back to that client call.
Yes.
> I understand that the client when it calls the server tells the
> server to send a response to a port (which is typically chosen by
> the client).
No.
When you call someone on the telephone, only *his* telephone number is
important, and only while establishing the connection. He doesn't need
to call you back to reply, because the initial connection works in
*both* directions,
Similarly, the server's port number is only interesting while the
client is connecting. It is a way for the client to reach the server,
and the client's port number is not relevant. Once the connection is
established, the port numbers are no longer interesting.
The client doesn't need to tell the server where to send the response
because the connection consists of two channels, one in each
direction. The server can send the response on the same socket that
the request arrived on.
Do you have any questions related to Java? A more suitable place for
this might be comp.protocols.tcp-ip.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Roedy Green - 11 Sep 2005 11:05 GMT
>The client doesn't need to tell the server where to send the response
>because the connection consists of two channels, one in each
>direction. The server can send the response on the same socket that
>the request arrived on.
See http://mindprod.com/jgloss/tcpip.html
Look at the packet format. It might become a little clearer.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Thomas Hawtin - 09 Sep 2005 13:42 GMT
> We have a Server written in C and the guy who is writing the server
> insists that he doesn't want to spawn a thread for every request from
> us stating that it is inefficient.
That's appears to be a clear case of premature optimisation. Probably
why the server is written in C in the first place.
You don't need a new thread for each job. Threads can be pooled.
Similarly processes can be pooled. For processes you would typically
have spares all listening on the same server socket.
Ball park figures for number of simultaneous connections for each
technique are very approximately: hundreds of processes, thousands of
threads or tens of thousands using non-blocking or asynchronous I/O.
I am confused as to what the advantages of using two ports are. If you
open TCP connections you are effectively doubling the workload.
However, if you are using UDP then I can understand. Two ports for two
parts of the protocol. Broadcasts shouldn't be coming back to the server.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/