⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serveraccept.java

📁 RemoteWAP is a Remote Administration Tool for any Operating System that can support the Java Virtual
💻 JAVA
字号:
/*
 *  ServerAccept.java
 *
 *  Copyright (C) 2004 Jay Scott
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program (gpl.txt); if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package server;

import commands.RunCommand;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import ui.ServerGUI;

/**
 *  This class gets the data that the client has sent to the server when they
 *  connected to the listening port. With this data the class decides what page
 *  the client is wanting to view and the passes this information to another
 *  class to be executed.
 *
 *@author     Jay Scott
 *@created July 21, 2004
 *@version    0.4
 */
public class ServerAccept {

    /**
     * Constructor for the ServerAccept object
     * 
     * @param x
     *            This holds the data sent by the user.
     * @param p
     *            This holds the Internet Protocol Address of the user.
     */
    ServerAccept(Socket x, InetAddress p) {

        Format TimeFormat;
        Date date = new Date();
        TimeFormat = new SimpleDateFormat("hh:mm:ss a");
        RunCommand command = new RunCommand();

        String theTime = TimeFormat.format(date);

        try {
            /* Read the data sent by the client into a variable */
            BufferedReader Input = new BufferedReader(new InputStreamReader(x
                    .getInputStream()));

            /* Declare a variable to send data back to the client */
            BufferedWriter ServerOutput = new BufferedWriter(
                    new OutputStreamWriter(x.getOutputStream()));

            /* Declare a string and store the data the client sent in it */
            String ServerInput = new String();
            ServerInput = Input.readLine();

            int requestPos = ServerInput.indexOf(" ") + 1;

            int requestEnd = ServerInput.indexOf(" ", requestPos);
            String RequestedFile = ServerInput.substring(requestPos + 1,
                    requestEnd);

            ServerGUI.StatusText.append('[' + theTime + ']' + " - " + p
                    + " Connected to server\n" + " \t - Data sent ("
                    + ServerInput + ")\n");

            /* process the users command */
            String completedCMD = command.runCommand(RequestedFile);

            /* Send default headers to mobile phone */
            ServerOutput.write("HTTP/1.1 200 OK \r\n");
            ServerOutput.write("Content-Type: text/vnd.wap.wml \r\n");
            ServerOutput.write("Connection: close \r\n");
            ServerOutput.write("\r\n");

            ServerOutput.write(completedCMD);
            ServerOutput.flush();
            Input.close();
            ServerOutput.close();

        } catch (Exception e) {
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -