Quadcap Embeddable Server

com/quadcap/net/server/Test.java

Go to the documentation of this file.
00001 package com.quadcap.net.server; 00002 00003 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved. 00004 * 00005 * This software is distributed under the Quadcap Free Software License. 00006 * This software may be used or modified for any purpose, personal or 00007 * commercial. Open Source redistributions are permitted. Commercial 00008 * redistribution of larger works derived from, or works which bundle 00009 * this software requires a "Commercial Redistribution License"; see 00010 * http://www.quadcap.com/purchase. 00011 * 00012 * Redistributions qualify as "Open Source" under one of the following terms: 00013 * 00014 * Redistributions are made at no charge beyond the reasonable cost of 00015 * materials and delivery. 00016 * 00017 * Redistributions are accompanied by a copy of the Source Code or by an 00018 * irrevocable offer to provide a copy of the Source Code for up to three 00019 * years at the cost of materials and delivery. Such redistributions 00020 * must allow further use, modification, and redistribution of the Source 00021 * Code under substantially the same terms as this license. 00022 * 00023 * Redistributions of source code must retain the copyright notices as they 00024 * appear in each source code file, these license terms, and the 00025 * disclaimer/limitation of liability set forth as paragraph 6 below. 00026 * 00027 * Redistributions in binary form must reproduce this Copyright Notice, 00028 * these license terms, and the disclaimer/limitation of liability set 00029 * forth as paragraph 6 below, in the documentation and/or other materials 00030 * provided with the distribution. 00031 * 00032 * The Software is provided on an "AS IS" basis. No warranty is 00033 * provided that the Software is free of defects, or fit for a 00034 * particular purpose. 00035 * 00036 * Limitation of Liability. Quadcap Software shall not be liable 00037 * for any damages suffered by the Licensee or any third party resulting 00038 * from use of the Software. 00039 */ 00040 00041 import java.io.ByteArrayInputStream; 00042 00043 import java.io.*; 00044 import java.net.*; 00045 00046 import java.util.Properties; 00047 00048 import com.quadcap.util.Debug; 00049 00050 /** 00051 * Package level testing. 00052 * 00053 * @author Stan Bailes 00054 */ 00055 public class Test { 00056 static String tst = "Text: foo\r\nSpaz: bar\r\n\r\n"; 00057 00058 public static void main(String args[]) { 00059 try { 00060 ServerSocket ss = new ServerSocket(80, 143); 00061 byte[] buf = new byte[11000]; 00062 while (true) { 00063 Socket s = ss.accept(); 00064 InputStream in = s.getInputStream(); 00065 OutputStream out = s.getOutputStream(); 00066 in.read(buf); 00067 out.write(buf, 0, buf.length); 00068 s.close(); 00069 } 00070 } catch (Throwable t) { 00071 Debug.print(t); 00072 } 00073 } 00074 00075 public static void main3(String args[]) { 00076 try { 00077 WorkerInputStream win = new WorkerInputStream(null); 00078 win.reset(new ByteArrayInputStream(tst.getBytes())); 00079 byte[] hbuf = new byte[1024]; 00080 int[] hoff = new int[16]; 00081 int cnt = win.readHeaders(hbuf, hoff); 00082 System.out.println("cnt = " + cnt); 00083 int hcnt = hoff[0]; 00084 for (int i = 0; i <= hcnt; i++) { 00085 System.out.println("hoff[" + i + "] = " + hoff[i]); 00086 } 00087 System.out.println("win.read() = " + win.read()); 00088 } catch (Throwable t) { 00089 Debug.print(t); 00090 } 00091 } 00092 00093 public static void main2(String args[]) { 00094 try { 00095 Properties p = new Properties(); 00096 p.put("workerClass", "com.quadcap.net.server.SimpleWorker"); 00097 Server s = new Server(p, null); 00098 00099 p = new Properties(); 00100 p.put("port", "80"); 00101 p.put("queueDepth", "64"); 00102 s.startAcceptor(p); 00103 } catch (Exception e) { 00104 e.printStackTrace(System.err); 00105 } 00106 } 00107 00108 }