Andrew Pollack's Blog

Technology, Family, Entertainment, Politics, and Random Noise

More on the generic server -- and some code.....

By Andrew Pollack on 04/29/2005 at 04:18 PM EDT

So I've finished two big pieces of the "current projects" list. Now I have a full blown DNS client that lets me pick a dns server and request any kind of data from it. That means I can do reverse lookups, pointer lookups, ownership checks, and real time black hole list lookups from my own code. So, how will I add that to a back end server?

Well, the way I've implemented my "Generic" server, all I have to do is create a new class which extends my base class called "NctSessionHandler" and override a single method, called "acceptData". That method gets called by the base class when the first command is sent to the server from a connecting client. When the method finishes, it drops back to the server and if another base command comes in, the method is called again. I "own" the session once its passed though. If I'm finished with it, I can call the built in method to terminate the session, then when I drop control back to the server it will wait for a new connection. If I fail to call that, the sever will time the connection out if there are no more commands. I can control the time out time however, so I could keep the session open for as long as I want. If I want to do more complex things, I have methods I can call to send data back to the client, or to wait for a response from the client (with a time out that I set, and a terminating character that I determine). I can also find out the address and port the user is connecting with. In short, its a fully functional server, but I don't have to work about any of the threading, connections, or complex infrastructure.

The code below is all I've had to do to create a running server capable of handling up to around a hundred simple connections per SECOND. The code accepts data across the connection in the form of simple strings of text, and responds back with the same string, reversed.

First, I create the new session handler class from the base class ---

class NctAntiSpamSessionHandler extends NctSessionHandler { 
    public void acceptData(String dataString) 
    {
        String backLine = "";         
        for(int z = dataString.length() ; z > 0 ; z-- )  
		backLine = backLine + dataString.substring(z, z + 1);
        sendData(backLine + "\n");        
    }        
}

That's it. That's the whole class. Now, below is the code to instantiate and launch the server. Notice that I'm passing it a sample handler of my own. The handler I pass it must be a subclass of the base "NctSessionHandler" class, which also extends Thread and implements Cloneable. The sever will use the handler (which has not been started) and make cloned copies for each thread it needs to run. It will make sure the parameters are either set to default, or that I've set them myself, then start each listener thread.

int port = 33900 ;
int threads = 100 ;
int maxQueue = 5 ;
NctAntiSpamSessionHandler asHander = new NctAntiSpamSessionHandler();
NctGenericServer server = new NctGenericServer(port, threads, maxQueue, asHander);
server.start();

Ok, so if you've wondered why I'd spend days working on something that can't do much more than parot back what you put in -- really fast -- consider that I now have an easy, flexible infrastructure for all kinds of back end server needs.


There are  - loading -  comments....

That would work well as a Domino Addin...By Julian Robichaux on 04/29/2005 at 09:25 PM EDT
That would work well in conjunction with the Java Domino server addin code too:

http://www.nsftools.com/tips/JavaTips.htm#javaaddin

And also, I probably would have used the variable "assHandler" for
AntiSpamSessionHandler, but that's just me...
;-)

- Julian
Thanks Julian -- I've been digging into this...By Andrew Pollack on 04/29/2005 at 09:59 PM EDT
... That code is actually really useful -- I'll have to look at the release
license before I decide to use it or not as I intend to produce commercial
software as well.

What I've been looking for is the next step up -- at least in documentation.
I'd like to hook and monitor -- perhaps even intercept -- port calls for other
services as part of the addin. In know iSpy does it. Thus far, I haven't
looked too hard but I haven't found a thing either. I did ask for a location
for formal doc of the runJava interface, but thus far I haven't heard a single
response other than one joke in reference to such a thing as formal
documentation existing.


Other Recent Stories...

  1. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino serverWhile a full description of OATH is way beyond what I can do in this quick blog entry, I wanted to talk a bit about how "SCOPES" interact with the already rich authorization model used by Domino. Thanks to the fantastic work by John Curtis and his team, the node.js integration with Domino is going to be getting a rich security model. What we know is that a user's authorizations will be respected through the node.js application to the Domino server -- including reader names, ACLs, Roles, and so on. The way ...... 
  2. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concernedDear Toro Customer Service, I arm writing about the following machine: Toro Power Max 1120 OXEModel:38654S/N:31000#### Specifically, bearing part #:63-3450 This is the part ($15 online / $25 at the local dealer) that caused me to raise my objections on-line. This piece of garbage is supposed to be a bearing. It carries the shaft which drives both stages of the auger. The shaft passes through the bearing (which is what bearings do) after the auger drive pulley as the shaft goes through the back (engine ...... 
  3. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me!Come find me in NYC on Wednesday at the Launch Event if you're there. I really do want to talk to ...... 
  4. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  5. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  6. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  7. 02/15/2018Andrew’s Proposed Gun Laws 
  8. 05/05/2016Is the growing social-sourced economy the modern back door into socialism? 
  9. 04/20/2016Want to be whitelisted? Here are some sensible rules for web site advertising 
  10. 12/30/2015Fantastic new series on Syfy called “The Expanse” – for people who love traditional science fiction 
Click here for more articles.....


pen icon Comment Entry
Subject
Your Name
Homepage
*Your Email
* Your email address is required, but not displayed.
 
Your thoughts....
 
Remember Me  

Please wait while your document is saved.