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

📄 linkserverstarter.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
字号:
// **********************************************************************// // <copyright>// //  BBN Technologies//  10 Moulton Street//  Cambridge, MA 02138//  (617) 873-8000// //  Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/link/LinkServerStarter.java,v $// $RCSfile: LinkServerStarter.java,v $// $Revision: 1.2.2.1 $// $Date: 2004/10/14 18:27:08 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.link;import java.net.ServerSocket;import java.net.Socket;/** * The LinkServerStarter is the object that listens for Link clients * on a specific port. If a Link client contacts it, it uses the * startNewServer method to create a LinkServer to serve the client on * it's own thread. If you want to create a new type of LinkServer, * you should also create a new LinkServerStarter to launch it * properly. Generally, the main() and startNewServer() methods are * the only thing you would need to modify. */public class LinkServerStarter {    /** Default port that the server starter listens to. */    public static final int DEFAULT_PORT = 3031;    /** The port being listened to. */    protected int serverPort;    /** Starts the LinkServerStarter listening to the default port. */    public LinkServerStarter() {        serverPort = DEFAULT_PORT;    }    /** Starts the LinkServerStarter listening to the specified port. */    public LinkServerStarter(int port) {        serverPort = port;    }    /** Set the port to listen for a connection request. */    public void setPort(int port) {        serverPort = port;    }    /** Get the port that is being listened to. */    public int getPort() {        return serverPort;    }    /**     * The method of the parent server that is listening for clients.     * When a contact is made, a child thread is spawned off to handle     * the client.     */    public void run() {        try {            ServerSocket serverSocket = new ServerSocket(serverPort);            Socket socket;            System.out.println("LinkServerStarter: running on port "                    + serverPort);            while (true) {                socket = serverSocket.accept();                System.out.println("LinkServer: fielding connection");                ((Thread) startNewServer(socket)).start();            }        } catch (java.io.IOException ioe) {            System.err.println("LinkServer: IOException while running:");            System.err.println(ioe);        }    }    /**     * This method gets called to create a new server to handle a new     * connection. Thread.start() will get called on the returned     * thread. This method should always get overridden.     *      * @param sock the socket connection     * @return a thread that will get started     * @see java.lang.Thread#start()     */    public Thread startNewServer(Socket sock) {        return new LinkServer(sock);    }    /**     * Start up the server. This is the method to change if you want     * to customize how the LinkServer will handle clients - port,     * arguments, etc.     */    public static void main(String[] argv) {        int pnumber = -1;        com.bbn.openmap.util.Debug.init();        for (int i = 0; i < argv.length; i++) {            if (argv[i].equals("-port") && argv.length > i + 1) {                try {                    pnumber = Integer.parseInt(argv[i + 1]);                    break;                } catch (NumberFormatException e) {                    pnumber = -1;                }            }        }        if (pnumber < 0) {            System.out.println("Need to start the server with a port number.");            System.out.println("Usage: java com.bbn.openmap.layer.link.LinkServerStarter -port <port number>");            System.exit(0);        }        System.out.println("LinkServerStarter: Starting up on port " + pnumber                + ".");        LinkServerStarter serverStarter = new LinkServerStarter(pnumber);        while (true) {            serverStarter.run();        }    }}

⌨️ 快捷键说明

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