Package java.net

Examples of java.net.ServerSocket


  public void run() {
    try {
      Socket client = null;
      int listenPort = Config.listen_port();
      ServerSocket ss = new ServerSocket(listenPort);
      logger.info("����" + listenPort + "�˿ڣ��ȴ��ͻ��˵�����...");
      while (true) {
        client = ss.accept();
        logger.info("���յ�������" + client.toString());
        SegmentService service = new SegmentService(dictLib, client);
        service.start();
      }
    } catch (IOException e) {
View Full Code Here


    */
   public void run()
   {
      try {
         int backlog = glob.getProperty().get("http.backlog", 50); // queue for max 50 incoming connection request
         this.listen = new ServerSocket(HTTP_PORT, backlog, InetAddress.getByName(ip_addr));
         while (running) {
            Socket accept = this.listen.accept();
            log.fine("New incoming request on bootstrapPort=" + HTTP_PORT + " ...");
            if (!running) {
               log.info("Closing http server bootstrapPort=" + HTTP_PORT + ".");
View Full Code Here

        }
      }

      mLog.info("Listening on port " + port + "...");
      try {
        mCurrentSocket = new ServerSocket(port);
      }
      catch (IOException exc) {
        throw new RegainException("Creating socket for port " + port + " failed.", exc);
      }
      mSimplewebConnection.connect(mCurrentSocket);
View Full Code Here

    if (this.serverThread != null)
      throw new IllegalStateException("SMTPServer already started");

    // Create our server socket here.
    ServerSocket serverSocket;
    try
    {
      serverSocket = this.createServerSocket();
    }
    catch (Exception e)
View Full Code Here

    else
    {
      isa = new InetSocketAddress(this.bindAddress, this.port);
    }

    ServerSocket serverSocket = new ServerSocket();
    // http://java.sun.com/j2se/1.5.0/docs/api/java/net/ServerSocket.html#setReuseAddress(boolean)
    serverSocket.setReuseAddress(true);
    serverSocket.bind(isa, this.backlog);

    if (this.port == 0)
    {
      this.port = serverSocket.getLocalPort();
    }

    return serverSocket;
  }
View Full Code Here

   
    public NioSocketServer(boolean useNIO) throws IOException {
        if (useNIO) {
            ServerSocketChannel ssc = ServerSocketChannel.open();
            ssc.configureBlocking(false);
            ServerSocket ss = ssc.socket();
            ss.bind(new InetSocketAddress(LISTEN_PORT));
           
            this.selector = Selector.open();
            ssc.register(this.selector, SelectionKey.OP_ACCEPT);
        } else {
            this.serverSocket = new ServerSocket(LISTEN_PORT);
            this.serverSocket.setSoTimeout(500);
        }

        this.thread = new Thread(this);
        this.thread.setDaemon(true);
View Full Code Here

    /**
     * The main run method. This handles the normal thread processing.
     */
    public void run() {
        try {
            ServerSocket ss = this.listenAddress == null ? new ServerSocket(
                    this.listenPort, BACKLOG_COUNT) : new ServerSocket(
                    this.listenPort, BACKLOG_COUNT, InetAddress
                            .getByName(this.listenAddress));
            ss.setSoTimeout(LISTENER_TIMEOUT);
            Logger.log(Logger.INFO, AJP_RESOURCES, "Ajp13Listener.StartupOK",
                    this.listenPort + "");

            // Enter the main loop
            while (!interrupted) {
                // Get the listener
                Socket s = null;
                try {
                    s = ss.accept();
                } catch (java.io.InterruptedIOException err) {
                    s = null;
                }

                // if we actually got a socket, process it. Otherwise go around
                // again
                if (s != null)
                    this.objectPool.handleRequest(s, this);
            }

            // Close server socket
            ss.close();
        } catch (Throwable err) {
            Logger.log(Logger.ERROR, AJP_RESOURCES,
                    "Ajp13Listener.ShutdownError", err);
        }

View Full Code Here

    /**
     * Gets a server socket - this is mostly for the purpose of allowing an
     * override in the SSL connector.
     */
    protected ServerSocket getServerSocket() throws IOException {
        ServerSocket ss = this.listenAddress == null ? new ServerSocket(
                this.listenPort, BACKLOG_COUNT) : new ServerSocket(
                this.listenPort, BACKLOG_COUNT, InetAddress
                        .getByName(this.listenAddress));
        return ss;
    }
View Full Code Here

     * and allocates any that it finds to a request handler thread, before going
     * back to listen again.
     */
    public void run() {
        try {
            ServerSocket ss = getServerSocket();
            ss.setSoTimeout(LISTENER_TIMEOUT);
            Logger.log(Logger.INFO, Launcher.RESOURCES, "HttpListener.StartupOK",
                    new String[] { getConnectorName().toUpperCase(),
                            this.listenPort + "" });

            // Enter the main loop
            while (!interrupted) {
                // Get the listener
                Socket s = null;
                try {
                    s = ss.accept();
                } catch (java.io.InterruptedIOException err) {
                    s = null;
                }

                // if we actually got a socket, process it. Otherwise go around
                // again
                if (s != null)
                    this.objectPool.handleRequest(s, this);
            }

            // Close server socket
            ss.close();
        } catch (Throwable err) {
            Logger.log(Logger.ERROR, Launcher.RESOURCES, "HttpListener.ShutdownError",
                    getConnectorName().toUpperCase(), err);
        }

View Full Code Here

     * The main run method. This handles the normal thread processing.
     */
    public void run() {
        boolean interrupted = false;
        try {
            ServerSocket controlSocket = null;

            if (this.controlPort > 0) {
                controlSocket = new ServerSocket(this.controlPort);
                controlSocket.setSoTimeout(CONTROL_TIMEOUT);
            }

            Logger.log(Logger.INFO, RESOURCES, "Launcher.StartupOK",
                    new String[] {RESOURCES.getString("ServerVersion"),
                                    (this.controlPort > 0 ? "" + this.controlPort
                                            : RESOURCES.getString("Launcher.ControlDisabled"))});

            // Enter the main loop
            while (!interrupted) {
//                this.objectPool.removeUnusedRequestHandlers();
//                this.hostGroup.invalidateExpiredSessions();

                // Check for control request
                Socket accepted = null;
                try {
                    if (controlSocket != null) {
                        accepted = controlSocket.accept();
                        if (accepted != null) {
                            handleControlRequest(accepted);
                        }
                    } else {
                        Thread.sleep(CONTROL_TIMEOUT);
                    }
                } catch (InterruptedIOException err) {
                } catch (InterruptedException err) {
                    interrupted = true;
                } catch (Throwable err) {
                    Logger.log(Logger.ERROR, RESOURCES,
                            "Launcher.ShutdownError", err);
                } finally {
                    if (accepted != null) {
                        try {accepted.close();} catch (IOException err) {}
                    }
                    if (Thread.interrupted()) {
                        interrupted = true;
                    }
                }
            }

            // Close server socket
            if (controlSocket != null) {
                controlSocket.close();
            }
        } catch (Throwable err) {
            Logger.log(Logger.ERROR, RESOURCES, "Launcher.ShutdownError", err);
        }
        Logger.log(Logger.INFO, RESOURCES, "Launcher.ControlThreadShutdownOK");
View Full Code Here

TOP

Related Classes of java.net.ServerSocket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.