亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? abstractserver.java

?? java版的簡(jiǎn)單聊天室程序
?? JAVA
字號(hào):
// This file contains material supporting section 3.8 of the textbook:// "Object Oriented Software Engineering" and is issued under the open-source// license found at www.lloseng.com package ocsf.server;import java.net.*;import java.io.*;/*** The <code> AbstractServer </code> class maintains a thread that waits* for connection attempts from clients. When a connection attempt occurs* it creates a new <code> ConnectionToClient </code> instance which* runs as a thread. When a client is thus connected to the* server, the two programs can then exchange <code> Object </code>* instances.<p>** Method <code> handleMessageFromClient </code> must be defined by* a concrete subclass. Several other hook methods may also be* overriden.<p>** Several public service methods are provided to applications that use* this framework, and several hook methods are also available<p>** Project Name: OCSF (Object Client-Server Framework)<p>** @author Dr Robert Lagani&egrave;re* @author Dr Timothy C. Lethbridge* @author Fran&ccedil;ois B&eacute;langer* @author Paul Holden* @version February 2001 (2.12)* @see ocsf.server.ConnectionToClient*/public abstract class AbstractServer implements Runnable{  // INSTANCE VARIABLES *********************************************  /**   * The server socket: listens for clients who want to connect.   */  private ServerSocket serverSocket = null;  /**   * The connection listener thread.   */  private Thread connectionListener;  /**   * The port number   */  private int port;  /**   * The server timeout while for accepting connections.   * After timing out, the server will check to see if a command to   * stop the server has been issued; it not it will resume accepting   * connections.   * Set to half a second by default.   */  private int timeout = 500;  /**   * The maximum queue length; i.e. the maximum number of clients that   * can be waiting to connect.   * Set to 10 by default.   */  private int backlog = 10;  /**   * The thread group associated with client threads. Each member of the   * thread group is a <code> ConnectionToClient </code>.   */  private ThreadGroup clientThreadGroup;  /**   * Indicates if the listening thread is ready to stop.  Set to   * false by default.   */  private boolean readyToStop = false;// CONSTRUCTOR ******************************************************  /**   * Constructs a new server.   *   * @param port the port number on which to listen.   */  public AbstractServer(int port)  {    this.port = port;    this.clientThreadGroup =      new ThreadGroup("ConnectionToClient threads")      {        // All uncaught exceptions in connection threads will        // be sent to the clientException callback method.        public void uncaughtException(          Thread thread, Throwable exception)        {          clientException((ConnectionToClient)thread, exception);        }      };  }// INSTANCE METHODS *************************************************  /**   * Begins the thread that waits for new clients.   * If the server is already in listening mode, this   * call has no effect.   *   * @exception IOException if an I/O error occurs   * when creating the server socket.   */  final public void listen() throws IOException  {    if (!isListening())    {      if (serverSocket == null)      {        serverSocket = new ServerSocket(getPort(), backlog);      }      serverSocket.setSoTimeout(timeout);      readyToStop = false;      connectionListener = new Thread(this);      connectionListener.start();    }  }  /**   * Causes the server to stop accepting new connections.   */  final public void stopListening()  {    readyToStop = true;  }  /**   * Closes the server socket and the connections with all clients.   * Any exception thrown while closing a client is ignored.   * If one wishes to catch these exceptions, then clients   * should be individually closed before calling this method.   * The method also stops listening if this thread is running.   * If the server is already closed, this   * call has no effect.   *   * @exception IOException if an I/O error occurs while   * closing the server socket.   */  final synchronized public void close() throws IOException  {    if (serverSocket == null)      return;      stopListening();    try    {      serverSocket.close();    }    finally    {      // Close the client sockets of the already connected clients      Thread[] clientThreadList = getClientConnections();      for (int i=0; i<clientThreadList.length; i++)      {         try         {           ((ConnectionToClient)clientThreadList[i]).close();         }         // Ignore all exceptions when closing clients.         catch(Exception ex) {}      }      serverSocket = null;      serverClosed();    }  }  /**   * Sends a message to every client connected to the server.   * This is merely a utility; a subclass may want to do some checks   * before actually sending messages to all clients.  This method   * can be overriden, but if so it should still perform the general   * function of sending to all clients, perhaps after some kind   * of filtering is done. Any exception thrown while   * sending the message to a particular client is ignored.   *   * @param msg   Object The message to be sent   */  public void sendToAllClients(Object msg)  {    Thread[] clientThreadList = getClientConnections();    for (int i=0; i<clientThreadList.length; i++)    {      try      {        ((ConnectionToClient)clientThreadList[i]).sendToClient(msg);      }      catch (Exception ex) {}    }  }// ACCESSING METHODS ------------------------------------------------  /**   * Returns true if the server is ready to accept new clients.   *   * @return true if the server is listening.   */  final public boolean isListening()  {    return (connectionListener != null);  }  /**   * Returns an array containing the existing   * client connections. This can be used by   * concrete subclasses to implement messages that do something with   * each connection (e.g. kill it, send a message to it etc.).   * Remember that after this array is obtained, some clients   * in this migth disconnect. New clients can also connect,   * these later will not appear in the array.   *   * @return an array of <code>Thread</code> containing   * <code>ConnectionToClient</code> instances.   */  synchronized final public Thread[] getClientConnections()  {    Thread[] clientThreadList = new      Thread[clientThreadGroup.activeCount()];    clientThreadGroup.enumerate(clientThreadList);    return clientThreadList;  }  /**   * Counts the number of clients currently connected.   *   * @return the number of clients currently connected.   */  final public int getNumberOfClients()  {    return clientThreadGroup.activeCount();  }  /**   * Returns the port number.   *   * @return the port number.   */  final public int getPort()  {    return port;  }  /**   * Sets the port number for the next connection.   * The server must be closed and restarted for the port   * change to be in effect.   *   * @param port the port number.   */  final public void setPort(int port)  {    this.port = port;  }  /**   * Sets the timeout time when accepting connections.   * The default is half a second. This means that stopping the   * server may take up to timeout duration to actually stop.   * The server must be stopped and restarted for the timeout   * change to be effective.   *   * @param timeout the timeout time in ms.   */  final public void setTimeout(int timeout)  {    this.timeout = timeout;  }  /**   * Sets the maximum number of waiting connections accepted by the   * operating system. The default is 20.   * The server must be closed and restarted for the backlog   * change to be in effect.   *   * @param backlog the maximum number of connections.   */  final public void setBacklog(int backlog)  {    this.backlog = backlog;  }// RUN METHOD -------------------------------------------------------  /**   * Runs the listening thread that allows clients to connect.   * Not to be called.   */  final public void run()  {    // call the hook method to notify that the server is starting    serverStarted();    try    {      // Repeatedly waits for a new client connection, accepts it, and      // starts a new thread to handle data exchange.      while(!readyToStop)      {        try        {          // Wait here for new connection attempts, or a timeout          Socket clientSocket = serverSocket.accept();          // When a client is accepted, create a thread to handle          // the data exchange, then add it to thread group          synchronized(this)          {            ConnectionToClient c = new ConnectionToClient(              this.clientThreadGroup, clientSocket, this);          }        }        catch (InterruptedIOException exception)        {          // This will be thrown when a timeout occurs.          // The server will continue to listen if not ready to stop.        }      }      // call the hook method to notify that the server has stopped      serverStopped();    }    catch (IOException exception)    {      if (!readyToStop)      {        // Closing the socket must have thrown a SocketException        listeningException(exception);      }      else      {        serverStopped();      }    }    finally    {      readyToStop = true;      connectionListener = null;    }  }// METHODS DESIGNED TO BE OVERRIDDEN BY CONCRETE SUBCLASSES ---------  /**   * Hook method called each time a new client connection is   * accepted. The default implementation does nothing.   * @param client the connection connected to the client.   */  protected void clientConnected(ConnectionToClient client) {}  /**   * Hook method called each time a client disconnects.   * The default implementation does nothing. The method   * may be overridden by subclasses but should remains synchronized.   *   * @param client the connection with the client.   */  synchronized protected void clientDisconnected(    ConnectionToClient client) {}  /**   * Hook method called each time an exception is thrown in a   * ConnectionToClient thread.   * The method may be overridden by subclasses but should remains   * synchronized.   *   * @param client the client that raised the exception.   * @param Throwable the exception thrown.   */  synchronized protected void clientException(    ConnectionToClient client, Throwable exception) {}  /**   * Hook method called when the server stops accepting   * connections because an exception has been raised.   * The default implementation does nothing.   * This method may be overriden by subclasses.   *   * @param exception the exception raised.   */  protected void listeningException(Throwable exception) {}  /**   * Hook method called when the server starts listening for   * connections.  The default implementation does nothing.   * The method may be overridden by subclasses.   */  protected void serverStarted() {}  /**   * Hook method called when the server stops accepting   * connections.  The default implementation   * does nothing. This method may be overriden by subclasses.   */  protected void serverStopped() {}  /**   * Hook method called when the server is clased.   * The default implementation does nothing. This method may be   * overriden by subclasses. When the server is closed while still   * listening, serverStopped() will also be called.   */  protected void serverClosed() {}  /**   * Handles a command sent from one client to the server.   * This MUST be implemented by subclasses, who should respond to   * messages.   * This method is called by a synchronized method so it is also   * implcitly synchronized.   *   * @param msg   the message sent.   * @param client the connection connected to the client that   *  sent the message.   */  protected abstract void handleMessageFromClient(    Object msg, ConnectionToClient client);// METHODS TO BE USED FROM WITHIN THE FRAMEWORK ONLY ----------------  /**   * Receives a command sent from the client to the server.   * Called by the run method of <code>ConnectionToClient</code>   * instances that are watching for messages coming from the server   * This method is synchronized to ensure that whatever effects it has   * do not conflict with work being done by other threads. The method   * simply calls the <code>handleMessageFromClient</code> slot method.   *   * @param msg   the message sent.   * @param client the connection connected to the client that   *  sent the message.   */  final synchronized void receiveMessageFromClient(    Object msg, ConnectionToClient client)  {    this.handleMessageFromClient(msg, client);  }}// End of AbstractServer Class

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线观看一区二区视频| 久久久综合精品| 91福利国产成人精品照片| 成人黄色av网站在线| 国产精品亚洲一区二区三区在线| 麻豆精品国产传媒mv男同| 日韩电影一二三区| 热久久一区二区| 欧洲另类一二三四区| 欧美体内she精高潮| 欧美美女一区二区| 制服视频三区第一页精品| 9191成人精品久久| 日韩美女一区二区三区| 日韩女优视频免费观看| 精品久久久久久久人人人人传媒| 精品免费日韩av| 久久综合色鬼综合色| 国产亚洲短视频| 国产精品福利一区二区三区| 亚洲人成网站精品片在线观看| 亚洲视频免费观看| 亚洲香蕉伊在人在线观| 青青草97国产精品免费观看| 九九精品一区二区| 高清不卡一区二区| 91美女在线视频| 欧美电影影音先锋| 日韩欧美国产一二三区| 久久久久久免费毛片精品| 亚洲欧洲成人精品av97| 亚洲在线观看免费| 日韩高清一区二区| 国产美女在线精品| 91蜜桃视频在线| 欧美一区二区三区在线视频 | 日韩小视频在线观看专区| 日韩欧美视频在线| 国产精品九色蝌蚪自拍| 亚洲国产精品久久艾草纯爱| 奇米在线7777在线精品| 国产精品99久| 欧美艳星brazzers| 久久综合九色综合欧美亚洲| 亚洲视频在线观看一区| 秋霞影院一区二区| 99国产精品国产精品毛片| 在线播放91灌醉迷j高跟美女| 国产无遮挡一区二区三区毛片日本| 国产精品久久国产精麻豆99网站| 亚洲国产毛片aaaaa无费看| 久久国产精品99精品国产| 成人小视频在线观看| 欧美精品一卡两卡| 国产精品二三区| 美女尤物国产一区| 91毛片在线观看| 久久综合精品国产一区二区三区| ...xxx性欧美| 国产一区视频网站| 欧美夫妻性生活| 国产精品久久三区| 精品亚洲免费视频| 欧美日韩国产一二三| 亚洲国产精品激情在线观看| 偷拍亚洲欧洲综合| 一本久道久久综合中文字幕| 久久综合色一综合色88| 日韩成人一区二区三区在线观看| av一二三不卡影片| 久久先锋影音av| 三级成人在线视频| 91麻豆123| 国产精品美女久久久久久久| 久久99九九99精品| 在线不卡中文字幕| 亚洲永久免费av| 99久久精品国产毛片| 国产网站一区二区三区| 蜜桃视频在线观看一区| 欧美日韩综合不卡| 亚洲欧美电影一区二区| 国产69精品一区二区亚洲孕妇| 日韩亚洲国产中文字幕欧美| 偷拍与自拍一区| 欧美日韩激情一区| 亚洲影院在线观看| 91极品视觉盛宴| 亚洲乱码国产乱码精品精小说| 国产不卡在线一区| 久久久精品2019中文字幕之3| 麻豆国产91在线播放| 欧美日韩国产电影| 亚洲成人动漫精品| 欧美亚洲一区二区在线| 亚洲激情五月婷婷| 色94色欧美sute亚洲13| 亚洲欧美激情视频在线观看一区二区三区| 国产成人av资源| 国产欧美日韩麻豆91| 国产精品白丝jk白祙喷水网站| 精品国产伦一区二区三区观看方式 | 亚洲一级二级在线| 色8久久精品久久久久久蜜| 日韩美女视频19| 91论坛在线播放| 一区二区欧美在线观看| 欧美最新大片在线看| 亚洲一区二区三区小说| 欧美日韩1区2区| 午夜精品国产更新| 欧美一级二级在线观看| 麻豆国产精品视频| 久久美女艺术照精彩视频福利播放| 久久国产成人午夜av影院| 亚洲精品一区二区三区蜜桃下载| 国内成+人亚洲+欧美+综合在线| 欧美精品一区二区三区高清aⅴ| 国产伦精品一区二区三区视频青涩 | 精品少妇一区二区三区免费观看| 麻豆精品新av中文字幕| 久久久精品tv| 91丝袜高跟美女视频| 亚洲一区二区美女| 日韩午夜在线观看| 国产精品1024| 亚洲欧美日韩小说| 欧美人与z0zoxxxx视频| 久久97超碰国产精品超碰| 久久久www成人免费毛片麻豆| 高清av一区二区| 一区二区三区四区在线| 欧美一级二级在线观看| 国产盗摄精品一区二区三区在线| 亚洲欧洲精品成人久久奇米网| 在线亚洲一区观看| 久久99精品久久久久久国产越南| 国产三级精品视频| 色94色欧美sute亚洲线路一ni| 日韩精品亚洲专区| 欧美国产成人精品| 欧美日韩综合不卡| 国产九九视频一区二区三区| 日韩一区在线看| 69堂国产成人免费视频| 懂色中文一区二区在线播放| 亚洲精品国产成人久久av盗摄 | 久久久久久久综合日本| 不卡一区二区三区四区| 丝袜美腿成人在线| 中文文精品字幕一区二区| 欧美日韩国产区一| 成人精品视频.| 日韩高清国产一区在线| 国产精品每日更新| 91精品久久久久久蜜臀| 不卡电影一区二区三区| 青青草国产成人99久久| 综合久久久久久| 欧美精品一区视频| 欧美综合亚洲图片综合区| 国产麻豆精品在线观看| 亚洲成av人片www| 国产精品免费aⅴ片在线观看| 欧美日本一区二区三区四区| 成人一区二区三区在线观看 | 成人黄色片在线观看| 青青草成人在线观看| 综合电影一区二区三区| 久久亚洲免费视频| 欧美精品久久天天躁| 91亚洲大成网污www| 国产精品资源站在线| 日韩国产一二三区| 一区二区在线电影| 中文字幕精品—区二区四季| 欧美电影免费观看高清完整版| 欧美午夜一区二区| 91丨九色丨蝌蚪丨老版| 国产成人三级在线观看| 蜜桃一区二区三区在线| 婷婷综合五月天| 亚洲午夜电影在线观看| 国产精品久久久爽爽爽麻豆色哟哟| 欧美不卡一二三| 欧美一二三区在线| 欧美日韩三级一区| 91豆麻精品91久久久久久| 99精品视频在线免费观看| 国产大片一区二区| 国产一区二区三区在线观看免费视频| 日韩 欧美一区二区三区| 亚洲最新视频在线播放| 亚洲色大成网站www久久九九| 国产欧美精品区一区二区三区| xf在线a精品一区二区视频网站| 日韩小视频在线观看专区| 日韩一区二区视频| 欧美一级片在线看| 欧美一级高清片|