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. 01/26/2023Better Running VirtualBox or VMWARE Virtual Machines on Windows 10+ Forgive me, Reader, for I have sinned. I has been nearly 3 years since my last blog entry. The truth is, I haven't had much to say that was worthy of more than a basic social media post -- until today. For my current work, I was assigned a new laptop. It's a real powerhouse machine with 14 processor cores and 64 gigs of ram. It should be perfect for running my development environment in a virtual machine, but it wasn't. VirtualBox was barely starting, and no matter how many features I turned off, it could ...... 
  2. 04/04/2020How many Ventilators for the price of those tanks the Pentagon didn't even want?This goes WAY beyond Trump or Obama. This is decades of poor planning and poor use of funds. Certainly it should have been addressed in the Trump, Obama, Bush, Clinton, Bush, and Reagan administrations -- all of which were well aware of the implications of a pandemic. I want a military prepared to help us, not just hurt other people. As an American I expect that with the ridiculous funding of our military might, we are prepared for damn near everything. Not just killing people and breaking things, but ...... 
  3. 01/28/2020Copyright Troll WarningThere's a copyright troll firm that has automated reverse-image searches and goes around looking for any posted images that they can make a quick copyright claim on. This is not quite a scam because it's technically legal, but it's run very much like a scam. This company works with a few "clients" that have vast repositories of copyrighted images. The trolls do a reverse web search on those images looking for hits. When they find one on a site that looks like someone they can scare, they work it like ...... 
  4. 03/26/2019Undestanding how OAUTH scopes will bring the concept of APPS to your Domino server 
  5. 02/05/2019Toro Yard Equipment - Not really a premium brand as far as I am concerned 
  6. 10/08/2018Will you be at the NYC Launch Event for HCL Domino v10 -- Find me! 
  7. 09/04/2018With two big projects on hold, I suddenly find myself very available for new short and long term projects.  
  8. 07/13/2018Who is HCL and why is it a good thing that they are now the ones behind Notes and Domino? 
  9. 03/21/2018Domino Apps on IOS is a Game Changer. Quit holding back. 
  10. 02/15/2018Andrew’s Proposed Gun Laws 
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.