快速业务通道

糞?酒汽議謹?殻HTTP捲暦匂 - 園殻秘壇利

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-21

糞?酒汽議謹?殻HTTP捲暦匂

扮寂:2011-01-07 BlogJava 蛎仟査

朔豚氏戟源宸倖捲暦匂?糞?厚謹議孔嬬?箭泌?

1.屶隔POST圭塀戻住

2.屶隔屈序崙議送勧僕

3.屶隔?殻学侃尖

4.寡喘NIO掲怦毘侘塀糞?

1package thread; 2 3import java.io.BufferedReader; 4import java.io.IOException; 5import java.io.InputStream; 6import java.io.InputStreamReader; 7import java.io.OutputStream; 8import java.io.PrintWriter; 9import java.net.ServerSocket; 10import java.net.Socket; 11 12/** *//** 13 *  Copyright (C): 2009 14 *  @author 蛎仟査 15 *  Jun 27, 2009 2:39:39 PM 16 */ 17 18/** *//** 19 * Threaded Network Server 20 * 宸頁匯倖酒汽議謹?殻HTTP捲暦匂 21 * 寡喘謹?殻栖侃尖互旺窟議喘薩萩箔 22 */ 23public class HttpServer { 24    public static void main(String [] args){ 25        HttpServer hs=new HttpServer(); 26        int i=1, port=8888; 27        Socket received=null; 28        try{ 29            ServerSocket server=new ServerSocket(port); 30            while(true){ 31                received=server.accept(); 32                if(received!=null){ 33                    hs.new ProcessThread(i++,received).start(); 34                } 35            } 36        }catch(IOException e){ 37            e.printStackTrace(); 38        } 39    } 40 41    class ProcessThread extends Thread 42    { 43        private int thread_number=0; 44        private Socket received=null; 45         46        public ProcessThread(int thread_number, Socket received) { 47            super(); 48            this.thread_number = thread_number; 49            this.received = received; 50        } 51 52        public void run() { 53            System.out.println("及"+thread_number+"倖侃尖?殻尼強阻……"); 54            if(received!=null){ 55                try{ 56                    System.out.println("銭俊喘薩議仇峽?"+received.getInetAddress().getHostAddress()); 57                    InputStream in=received.getInputStream(); 58                    BufferedReader d= new BufferedReader(new InputStreamReader(in)); 59                    String result=d.readLine(); 60                    while(result!=null && !result.equals("")){ 61                        System.out.println(result); 62                        result=d.readLine(); 63                    } 64                    OutputStream out=received.getOutputStream(); 65                    PrintWriter outstream=new PrintWriter(out,true); 66                    String msg1="<html><head><title></title></head><body><h1>辺欺?</h1></body></html>"; 67                    outstream.println("HTTP/1.0 200 OK");//卦指哘基?連,旺潤崩哘基 68                    outstream.println("Content-Type:text/html;charset=GBK"); 69                    outstream.println();// 功象 HTTP 亅咏, 腎佩繍潤崩遊佚連 70                    outstream.println(msg1); 71                    outstream.flush(); 72                    outstream.close(); 73                }catch(IOException e){ 74                    e.printStackTrace(); 75                }finally{ 76                    try{ 77                        received.close(); 78                    }catch(IOException e){ 79                        e.printStackTrace(); 80                    } 81                } 82            } 83        } 84    } 85} 86

塰佩宸倖殻會尼強捲暦匂?隼朔壓箝誓匂仇峽生補秘?http://localhost:8888/?軸辛心欺卦指潤惚。

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号