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

📄 connectionserver.java

📁 一个agent 工具包,可以开发移动设备应用,考虑了安全措施
💻 JAVA
字号:
package SOMA.network.connection;

import java.net.*;
import java.io.*;

/** Server in attesa di {@link SOMA.network.connection.Connection connessioni}.
*
* @see SOMA.network.connection.NewServerExplorerItem
*
* @author Livio Profiri
*/
public class ConnectionServer implements Runnable, Daemon
{
  Thread myServerDaemon = null;
  ServerSocket myServerSocket = null;
  ConnectionFactory myConnectionFactory = null;

  Object status = OFF;
  String ErrorDescription = "";

  int port = 0;
  int backlog = 50;

  /** Costruttore.
  * @param port Porta su cui si attendono connessioni.
  * @param backlog Numero massimo di connessioni contemporanee.
  * @param myConnectionFactory Classe responsabile della creazione delle connessioni.
  */
  public ConnectionServer(int port, int backlog, ConnectionFactory myConnectionFactory )
  {
    this.port = port;
    this.backlog = backlog;
    this.myConnectionFactory = myConnectionFactory;
  }

  /** Restituisce lo stato. */
  public Object getStatus()
  {
    return status;
  }

  /** Avvia il server. */
  public synchronized void start() throws IOException, ConnectionServerException
  {
    if( status != ON )
    {
      try
      {
        myServerSocket = new ServerSocket( port, backlog );

        myServerDaemon = new Thread( this, toString() );

        /*
        try
        {
          myServerDaemon.setContextClassLoader(ClassLoader.getSystemClassLoader());
        }
        catch( Exception e )
        {
          e.printStackTrace();
        }*/

        status = ON;

        myServerDaemon.start();
      }
      catch( IOException e )
      {
        status = ERROR;
        ErrorDescription = e.toString();
        throw( e );
      }
    }
    else
      throw new ConnectionServerException( "Server already ON" );
  }

  /** Arresta il server. */
  public synchronized void stop() throws IOException, ConnectionServerException
  {
    if( status != OFF )
    {
      try
      {
        status = OFF;

        if( myServerSocket != null )
          myServerSocket.close();

        // Vedo se cos

⌨️ 快捷键说明

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