📄 simpleserver.java
字号:
/*================= * Copyright (C) 2001 Hajime Inoue * * Lisys is a program that monitors TCP SYN packets to detect network * traffic anomalies. * * Licensed under the GNU General Public License (GPL), version 2 or * higher. Please see the COPYING and PATENT files included with the * Lisys distribution, which can be found at: * * http://www.cs.unm.edu/~judd/lisys/ * * Also, the current text of the GPL can be found at: * * http://www.gnu.org/copyleft/gpl.html * * Note that Lisys has NO WARRANTY! *=================*/package edu.unm.cs.lisys.net;import java.io.InputStream;import java.io.OutputStream;import java.io.*;import java.net.ServerSocket;import java.net.Socket;import edu.unm.cs.lisys.debug.*;/**========== * SimpleServer.java * A very simple single-threaded abstract class that allows for easy * implementation of servers using a single function. * * This is written to accomodate the new design of DetectionNode, * though it is general enough to handle HTTP service duties as * well, if they are very low bandwidth. * * Here are the people who have worked on this code in the order they * have worked on it: * @author Hajime Inoue <hinoue@cs.unm.edu> * @author Justin Balthrop <judd@cs.unm.edu> *==========*/public abstract class SimpleServer extends Thread implements Serializable{ protected int port; /**========== * run: * The run function accepts connections and hands them off * to the serveConnection function to deal with. * * NOTE - this is not multithreaded. No intensive computations * should occur in serveConnection. *==========*/ public void run() { Debug.verbose("In run()"); ServerSocket server; try { server = new ServerSocket(port, 16); } catch(Exception e) { Debug.exception(this,e); return; } while(true) { try { Socket s = server.accept(); Debug.verbose("Opened Connection"); try { System.err.println("Serving Connection"); s.setSoTimeout(10000); serveConnection(s.getInputStream(), s.getOutputStream()); s.close(); } catch(Exception e) { s.close(); Debug.exception(this,e); } Debug.verbose("Closed Connection"); } catch (Exception e) { Debug.exception(this,e); } System.gc(); } } /**========== * serveConnection: * Subclasses implement this function. * * @param in The inputstream of the socket * @param out The outputstream of the socket *==========*/ public abstract void serveConnection (InputStream in, OutputStream out) throws Exception; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -