Article View: borland.public.jbuilder.java.api
Article #1795Re: Quick question about sockets.
From: Joi Ellis [TeamB]
Date: Fri, 07 Sep 2001 14:10
Date: Fri, 07 Sep 2001 14:10
78 lines
3882 bytes
3882 bytes
Alex Colic <alex.colic@pop-ware.com> wrote: > Ok, got the book looking at the examples. > Question: the apps that are doing the listening are a bunch of web apps > jsp/servlets. Lets say I have 5 of them and they all need to listen on this > port. If I create a monitor class that uses a ServerSocket than I can only > have one of these web apps listening. Hrm. I thought Jsp/servlets run only when the web server is processing a page request. You don't want to use jsp/servlets for this, I don't think. > How about creating one monitor class that starts when the web server starts. > Then all my web apps register with this monitor class to receive commands. Yes. The monitor class has to know just enough about the commands to know which thread it should launch to process the incoming request. > 1: should this monitor class be a servlet? I don't think so, no. It needs to be running all the time, even before your web server receives requests. > 2: how can I get the monitor class to start when the server starts? I add it to the system startup script, rc.local, on my linux box. > 3: how can classes in other web applicatons register themselves with this > servlet? Probably in any way you choose. You'd write the monitor class so you can decide what sort of registration you need. A simple way to do it is to have the other apps write a config file some place where the monitor class can find them when it launches. > Thanks for any help. > Alex > "Joi Ellis [TeamB]" <joi@aravox.com> wrote in message > news:3b98cc80_1@dnews... >> Alex Colic <alex.colic@pop-ware.com> wrote: >> > Hi, >> >> > Ok I am obviously doing something wrong. I picked the ServerSocket > class >> > because I do not know what host is going to send me commands, just the > port. >> >> > Any idea how I can have more than one class just listen to the same port > for >> > commands? >> >> You can't. The general idea for this is to have a class that does nothing >> but listen, then spawns threads to handle incoming connections. Once the >> child threads have their sockets, the parent goes back to listening for >> more connections. >> >> This is pretty much how inetd works on *nix. There are examples of doing > this >> in Java in the O'Reilly 'Java Networking' book, among others. >> >> -- >> Joi Ellis (TeamB) http://www.teamb.com/ >> No direct email, please. >> For best results, post on news server newsgroups.borland.com! >> Newsgroup Guidelines: http://www.borland.com/newsgroups/guide.html >> Only posts which violate the rules in guide.html are subject to > cancelation. -- Joi Ellis (TeamB) http://www.teamb.com/ No direct email, please. For best results, post on news server newsgroups.borland.com! Newsgroup Guidelines: http://www.borland.com/newsgroups/guide.html Only posts which violate the rules in guide.html are subject to cancelation.
Technical Details
Message-ID:
<3b98d542_1@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!btnet-peer0!btnet-peer!btnet!diablo.netcom.net.uk!netcom.net.uk!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!dnews!not-for-mailReferences:
<3b97d61e_1@dnews> <3b9859d6$1_2@dnews> <3b98be46$1_2@dnews> <3b98cc80_1@dnews> <3b98d3f5_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,75eb349919d2da57
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2001-09-07 07:13:15 PST
Message-ID: <3b98d542_1@dnews>
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: Quick question about sockets.
Newsgroups: borland.public.jbuilder.java.api
References: <3b97d61e_1@dnews> <3b9859d6$1_2@dnews> <3b98be46$1_2@dnews> <3b98cc80_1@dnews> <3b98d3f5_1@dnews>
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.16-3 (i686))
NNTP-Posting-Host: 209.46.41.66
Date: 7 Sep 2001 07:10:11 -0700
X-Trace: dnews 999871811 209.46.41.66 (7 Sep 2001 07:10:11 -0700)
Lines: 78
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!btnet-peer0!btnet-peer!btnet!diablo.netcom.net.uk!netcom.net.uk!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!dnews!not-for-mail