You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by chamarthi vinod <ch...@gmail.com> on 2007/11/21 13:37:21 UTC

We are trying to implement a genericservlet to handle messages over tcp

please suggest better way or send some implementation code for the following
:


1. How the TCP/IP client request over a socket received at the tomcat? Is
there a configuration to specify the port on which TCP client has to send
the request?

Or the client shall use the same 8080 port for connecting over TCP also?

2. Does container support TCP sockets typically or we need to configure ?

3. How tomcat interprets the tcp/ip socket message to a servletrequest and
servlet response object?

4. If possible please provide the sample code for the above ?

Thanks in Advance.

Vinod.

Re: We are trying to implement a genericservlet to handle messages over tcp

Posted by Bill Barker <wb...@wilshire.com>.
"chamarthi vinod" <ch...@gmail.com> wrote in message 
news:3d6697260711210437g462cad38td1d59362bddde19f@mail.gmail.com...
> please suggest better way or send some implementation code for the 
> following
> :
>
>
> 1. How the TCP/IP client request over a socket received at the tomcat? Is
> there a configuration to specify the port on which TCP client has to send
> the request?
>
> Or the client shall use the same 8080 port for connecting over TCP also?
>

By convention, it is the 'port' attribute on the <Connector /> element.  But 
this isn't inforced.

> 2. Does container support TCP sockets typically or we need to configure ?
>

At the moment, Tomcat only works with TCP sockets ;).  The question is the 
message protocol that is coming over the socket.  Out-of-the-box, Tomcat 
only supports HTTP/1.1 and AJP/1.3 as messaging protocols.  But there is 
nothing to stop anyone writing support for another.  It looks like you are 
after a custom ProtocolHandler (see below), so 
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/tomcat/util/net/PoolTcpEndpoint.html 
may provide the basic socket and thread handling you need to implement it 
(assuming you don't need to do fancy stuff like NIO).

> 3. How tomcat interprets the tcp/ip socket message to a servletrequest and
> servlet response object?
>

Tomcat uses the Coyote interfaces from: 
http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/coyote/package-summary.html 
to translate between tcp/ip socket (or any other transport protocol, for 
that matter) messages and Request/Response objects.  Specifically it is the 
job of the ProtocolHandler to parse the incoming message into a 
Request/Response object pair, assign it to a thread, and hand it back to the 
Adapter to get sent to the target Servlet.

You tell Tomcat to use your ProtocolHandler via <Connector 
protocol="com.myfirm.mypackage.MyProtocolHandler" ... />.  All other 
attributes on the <Connector /> element will get passed through to the 
instance of MyProtocolHandler, so you can have any configuration directives 
that you like.

> 4. If possible please provide the sample code for the above ?
>

Starting with org.apache.coyote.ajp.AjpProtocol (in TC 6.x) is probably the 
simplest tcp/ip example.  (MemoryProtocolHandler is simpiler, but it doesn't 
do tcp/ip, so it is mostly useful as a mock Connector for unit testing 
Embedded Tomcats).  There is also org.apache.coyote.http11.Http11Protocol, 
which is more complicated since HTTP/1.1 is a more complicated protocol than 
AJP/1.3 :).

> Thanks in Advance.
>
> Vinod.
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org