dev@grizzly.java.net

Using Grizzly to capture logs from a Socket

From: Chad Gallemore <cgallemore_at_gestalt-llc.com>
Date: Fri, 13 Jul 2007 11:37:34 -0500

Hi,

 

We are looking to use Grizzly to start up listening on a port and accept
TCP packets that are sent from a logger (java.util.SocketHandler). I am
having trouble finding out how exactly we accomplish this. I've used
Grizzly as an http listener, which obviously doesn't work in this
situation. Below is what I have now, and I am wanting to refactor that
out to utilize Grizzly to accomplish the same task:

 

Public static void main (String [] args) {

    ServerSocket ss = new ServerSocket(8888);

 

    while (true) {

         final Socket socket = ss.accept();

         //Spin off a new thread to handle the rest of the processing.

         Runnable r = new Runnable() {

              public void run() {

                  try {

                      processData(socket);

                   } catch (Exception e) {

                       e.printStackTrace(); //To change body of catch
statement use File | Settings | File Templates.

                   }

               }

           };

    new Thread(r).start();

        }

}

 

Instead I was hoping to do something like the following, with my adapter
able to handle all of my processing, I later realized this won't work
because it only works over HTTP. Is there a way

That I can achieve the same thing over TCP:

 

Public static void main (String [] args) {

    selectorThread.setPort(8888);

    selectorThread.setAdapter(new NmrObserverProcessorAdapter(handler));

    selectorThread.initEndpoint();

 

     Runnable run = new Runnable() {

            public void run() {

                try {

                    System.out.println("starting selector thread
endpoint");

                    selectorThread.startEndpoint();

                } catch (Throwable t) {

                    System.out.println(t);

                    log.severe("Error starting endpoint for server " +
t);

                }

            }

        };

 

        Thread t = new Thread(run);

        t.setDaemon(true);

        t.start();

}

 

Thanks for the help.

 

Chad Gallemore

407 Pennsylvania Ave, Suite 201, Joplin, MO 64801

(417) 626-6510 (w)

(909) 528-9405 (c)

(417) 625-1810 (f)

http://gallemore.blogspot.com/ <http://gallemore.blogspot.com/>
<http://cgallemore@blogspot.com/>