<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ★33°空間‰


                           ----★七彩服飾  【最潮拜☆日單精品】【Esprit】【Hotwind】滿150包郵-女裝-流行女裝    www.7color.hb.cn

                           ----智力比知識重要,素質比智力重要,覺悟比素質更重要
    posts - 110,comments - 35,trackbacks - 0
    import java.net.*;???

    import java.util.*;???



    public class pop3server{???

    private static final int SERVER_PORT=110;???

    private static final int MAX_CLIENT=500;???

    private ServerSocket listenSocket=null;???

    private boolean keeprunning=true;???

    private InetAddress ip;???

    public static void main(String[] args){???

    pop3server server=new pop3server();???

    server.impserver();???

    }???

    public void impserver(){???

    Socket clientSocket=null;???

    try{???

    while(keeprunning){???

    clientSocket=listenSocket.accept();???

    int numThreads=Thread.activeCount();???

    System.out.println(numThreads);???

    manageconnection newhandle=new manageconnection(clientSocket);???

    Thread newhandlethread=new Thread(newhandle);???

    newhandlethread.start();???

    System.out.println("hello");???



    }???

    }???

    catch(IOException excpt){???

    System.err.println("Sorry ,Failed I/O:"+excpt);???

    }???



    }???



    public pop3server()???

    {???

    try{???

    listenSocket=new ServerSocket(SERVER_PORT,MAX_CLIENT);???

    }catch(IOException excpt){???

    System.err.println("SOrry to open port "+SERVER_PORT+":"+excpt);???

    System.exit(1);???

    }???

    }???

    }???



    /*follow is manage and process command class*/???



    class manageconnection implements Runnable{???

    private static final boolean AUTOFLUSH=true;???

    private Socket mySocket=null;???

    private PrintWriter out=null;???

    private BufferedReader in=null;???

    private boolean checkedpass=false;???

    private int msgnum=0;???

    private long[] msgsize=new long[100];???

    private long totalsize=0;???

    private String username=null;???

    public manageconnection(Socket newSocket){???

    mySocket=newSocket;???

    }???

    public void run(){???

    String nextline=null;???

    String password;???

    int check=0;???

    int strlen;???

    String content="Subject:hello";???

    String command=null;???

    String auth_user="user";???

    String arg1;???

    int arg2=0;???

    String arg3;???

    int i=0;???

    int count=0;???

    int time=0;???

    try{Thread.currentThread().sleep(10);???

    }catch(Exception e){???

    System.out.println(e);???

    }???

    try{???

    mySocket.setTcpNoDelay(true);???

    time=mySocket.getSoTimeout();???

    }catch(SocketException excpt){???

    System.out.println(excpt);???

    }???

    try{???

    out=new PrintWriter(mySocket.getOutputStream(),AUTOFLUSH);???

    in=new BufferedReader(new InputStreamReader(mySocket.getInputStream())

    ???

    );???

    /*System.out.println("hello thread1");*/???

    out.println("+OK"+" TianHua's pop3 server");???

    try{???

    while(true){???

    if(check!=3){???

    try{???

    nextline=in.readLine();}catch(Exception excpt){???

    System.out.println("sorry:"+excpt);???

    break;???

    }???

    System.out.println(count+" "+nextline);???



    if(nextline.length()<4){

    out.println("-ERR");

    }else{

    command=nextline.substring(0,4);

    if(command.equalsIgnoreCase("user")){

    i=1;

    }

    if(command.equalsIgnoreCase("pass")){

    i=2;

    }

    if(command.equalsIgnoreCase("stat")){

    i=3;

    }

    if(command.equalsIgnoreCase("quit")){

    i=4;

    }

    if(command.equalsIgnoreCase("list")){

    i=5;

    }

    if(command.equalsIgnoreCase("retr")){

    i=6;

    }

    if(command.equalsIgnoreCase("dele")){

    i=7;

    }



    switch(i){

    case 1:if(check==0){

    check=1;

    if(nextline.length()<5){

    out.println("-ERR");

    }else{arg1=nextline.substring(5);

    username=arg1;

    out.println("+OK");

    }

    }else{out.println("-ERR");}

    i=0;

    break;

    case 2:if(check==1){

    if(nextline.length()<5){

    out.println("-ERR");

    }else{

    arg1=nextline.substring(5);

    password=arg1;

    if(check(username,password)=='1'){

    check=2;

    /*msgnum=readmail(username);*/

    out.println("+OK");}else{

    out.println("-ERR"+" sorry auth failed");

    check=0;}

    }

    }else{out.println("-ERR");}

    i=0;

    break;

    case 3:if(check==2){

    msgnum=readmail(username);

    out.println("+OK"+" "+msgnum+" "+totalsize);

    }else{

    out.println("-ERR");

    }

    i=0;

    break;

    case 4:out.println("+OK BYE BYE welcome to TianHua's Mail System next



    time");

    check=3;

    i=0;

    break;

    case 5:if(check==2){

    out.println("+OK");

    out.println(msgnum+" "+totalsize);

    int ii,iii=0;

    for(ii=1;ii<=msgnum;ii++){

    out.println(ii+" "+msgsize[iii]);

    iii++;

    }

    out.println(".");

    }else{

    out.println("-ERR");

    }

    i=0;

    break;

    case 6:if(check==2){

    if(nextline.length()<5){

    out.println("-ERR");

    }else{

    arg1=nextline.substring(5);

    out.println("+OK");

    System.out.println(arg1);

    printmail(Integer.parseInt(arg1),username);

    out.print("\r\n");

    out.print(".");

    out.print("\r\n");

    boolean st=out.checkError();

    System.out.println(st);

    /*if(nextline.length()<6){

    out.println("-ERR");

    }else{

    try{

    arg2=Integer.parseInt(nextline.substring(5));

    }catch(NumberFormatException except)

    {

    out.println("-ERR");

    break;

    }

    if(msgnum==0){

    out.println("-ERR no msg retrived");

    }

    if(arg2<=msgnum){

    out.println("+OK");

    out.println(content);

    out.println("");

    out.print(".");

    out.println();

    out.println(".");

    System.out.println("msg finished");

    }else{

    out.println("no such msg");

    }

    }*/

    }

    }else{out.println("-ERR");

    }

    i=0;

    System.out.println("retr finished");

    break;

    case 7:if(check==2){

    out.println("+OK");

    }else{

    out.println("-ERR");

    }

    i=0;

    break;

    default:out.println("-ERR");

    i=0;

    break;





    }

    }

    }else{

    out.close();

    in.close();

    mySocket.close();

    break;

    }



    }

    }catch(NullPointerException excpt){

    System.out.println("sorry "+excpt);

    in.close();

    out.close();

    mySocket.close();

    }



    }catch(IOException excpt){

    System.err.println("Failed I/O:"+excpt);

    }



    System.out.println("bye");



    }

    private void printmail(int msgnumber,String uname){

    String msgdir="/webmail/userinfo/";

    String msgfile=msgdir+uname+"/"+Integer.toString(msgnumber);

    System.out.println(msgfile);

    long filepoint=0;

    try{

    RandomAccessFile file=new RandomAccessFile(msgfile,"r");

    long msglength=file.length();

    while(filepoint<msglength){

    String s=file.readLine();

    out.println(s);

    try{

    Thread.currentThread().sleep(5);

    }catch(Exception e){

    System.out.println(e);

    }

    filepoint=file.getFilePointer();

    }

    }catch(Exception e){

    System.out.println(e);

    }



    }





    /*check your username and password*/

    private char check(String user,String pass){

    String[] arg=new String[2];

    int c=0;

    char value='0';

    arg[0]="uname="+user;

    arg[1]="pass="+pass;



    try{



    Process child=Runtime.getRuntime().exec("/disk2/ftp/pub/login"



    ,arg);

    InputStream inn =child.getInputStream();

    while((c=inn.read())!=-1){

    value=(char)c;

    }

    inn.close();



    try{child.waitFor();}catch(InterruptedException e){



    e.printStackTrace();

    }



    }catch(IOException e){

    System.err.println(e);

    }

    return value;



    }





    private int readmail(String uname){

    String[] arg=new String[1];

    arg[0]="username="+uname;

    int[] msg=new int[3];

    int i=0,j=0;

    int msgnum=0;

    int c;

    try{

    Process child=Runtime.getRuntime().exec("/disk2/ftp/pub/readmail",



    arg);

    InputStream inn =child.getInputStream();

    while((c=inn.read())!=-1){

    msg
    =c-48;

    i++;

    }

    inn.close();

    try{child.waitFor();}catch(InterruptedException e){

    e.printStackTrace();

    }

    }catch(IOException e){

    System.err.println(e);

    }

    for(j=0;j<=i;j++){

    msgnum=msgnum+msg[j];

    }

    System.out.println(msgnum);

    int k=0;

    try{

    for(j=1;j<=msgnum;j++){

    RandomAccessFile file=new RandomAccessFile("/webmail/userinfo/"+uname+



    "/"+Integer.toString(j),"r");

    msgsize[k]=file.length();

    totalsize=msgsize[k]+totalsize;

    System.out.println(msgsize[k]);

    k++;

    }

    }catch(Exception e){

    System.out.println(e);

    }

    System.out.println(totalsize);

    return msgnum;

    }



    }??
    posted on 2006-09-29 14:35 圣域飛俠 閱讀(1575) 評論(0)  編輯  收藏 所屬分類: 個人心得
    主站蜘蛛池模板: 91精品免费高清在线| 亚洲精品视频免费观看| 国产91色综合久久免费分享| 国产精品久久久亚洲| 99视频在线观看免费| 亚洲精品无码永久在线观看你懂的| 本道天堂成在人线av无码免费| 亚洲无码黄色网址| 久久国产精品免费一区| 亚洲AV无码一区二区乱孑伦AS| 午夜理伦剧场免费| 亚洲第一二三四区| 无码专区永久免费AV网站| 亚洲国产精华液2020| 免费大片黄手机在线观看| 国产大片免费天天看| 久久精品国产亚洲精品2020| 亚洲视频在线观看免费视频| 亚洲六月丁香婷婷综合| 国产女高清在线看免费观看| 一本一道dvd在线观看免费视频 | 污视频网站在线观看免费| 国产亚洲?V无码?V男人的天堂 | 亚洲人成7777影视在线观看| 好男人www免费高清视频在线| 亚洲色最新高清av网站| 亚洲国产精品成人一区| APP在线免费观看视频| 亚洲成人动漫在线观看| 国产美女a做受大片免费| 青青草国产免费国产是公开| 久久久久国产亚洲AV麻豆| 久久国产免费一区二区三区| 亚洲夂夂婷婷色拍WW47| 久久久久一级精品亚洲国产成人综合AV区| 国产成人免费ā片在线观看老同学| 亚洲国产精品成人精品小说| 免费人成年轻人电影| 免费无遮挡无码永久视频| 最新亚洲人成网站在线观看| 国产亚洲精品岁国产微拍精品|