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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? abstractclient.java

?? java版的簡單聊天室程序
?? JAVA
字號:
// This file contains material supporting section 3.7 of the textbook:// "Object Oriented Software Engineering" and is issued under the open-source// license found at www.lloseng.com package ocsf;import java.io.*;import java.net.*;/*** The <code> AbstractClient </code> contains all the* methods necessary to set up the client side of a client-server* architecture.  When a client is thus connected to the* server, the two programs can then exchange <code> Object </code>* instances.<p>** Method <code> handleMessageFromServer </code> must be defined by* a concrete subclass. Several other hook methods may also be* overriden.<p>** Several public service methods are provided to* application that use this framework.<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&eacutel;langer* @author Paul Holden* @version February 2001 (2.12)*/public abstract class AbstractClient implements Runnable{// INSTANCE VARIABLES ***********************************************  /**  * Sockets are used in the operating system as channels  * of communication between two processes.  * @see java.net.Socket  */  private Socket clientSocket;  /**  * The stream to handle data going to the server.  */  private ObjectOutputStream output;  /**  * The stream to handle data from the server.  */  private ObjectInputStream input;  /**  * The thread created to read data from the server.  */  private Thread clientReader;  /**  * Indicates if the thread is ready to stop.  * Needed so that the loop in the run method knows when to stop  * waiting for incoming messages.  */  private boolean readyToStop= false;  /**  * The server's host name.  */  private String host;  /**  * The port number.  */  private int port;// CONSTRUCTORS *****************************************************  /**   * Constructs the client.   *   * @param  host  the server's host name.   * @param  port  the port number.   */  public AbstractClient(String host, int port)  {    // Initialize variables    this.host = host;    this.port = port;  }// INSTANCE METHODS *************************************************  /**   * Opens the connection with the server.   * If the connection is already opened, this call has no effect.   *   * @exception IOException if an I/O error occurs when opening.   */  final public void openConnection() throws IOException  {    // Do not do anything if the connection is already open    if(isConnected())      return;    //Create the sockets and the data streams    try    {      clientSocket= new Socket(host, port);      output = new ObjectOutputStream(clientSocket.getOutputStream());      input = new ObjectInputStream(clientSocket.getInputStream());    }    catch (IOException ex)    // All three of the above must be closed when there is a failure    // to create any of them    {      try      {        closeAll();      }      catch (Exception exc) { }      throw ex; // Rethrow the exception.    }    clientReader = new Thread(this);  //Create the data reader thread    readyToStop = false;    clientReader.start();  //Start the thread  }  /**   * Sends an object to the server. This is the only way that   * methods should communicate with the server.   *   * @param msg   The message to be sent.   * @exception IOException if an I/O error occurs when sending   */  final public void sendToServer(Object msg) throws IOException  {    if (clientSocket == null || output == null)      throw new SocketException("socket does not exist");    output.writeObject(msg);  }  /**   * Closes the connection to the server.   *   * @exception IOException if an I/O error occurs when closing.   */  final public void closeConnection() throws IOException  {    // Prevent the thread from looping any more    readyToStop= true;    try    {      closeAll();    }    finally    {      // Call the hook method      connectionClosed();    }  }// ACCESSING METHODS ------------------------------------------------  /**   * @return true if the client is connnected.   */  final public boolean isConnected()  {    return clientReader!=null && clientReader.isAlive();  }  /**   * @return the port number.   */  final public int getPort()  {    return port;  }  /**   * Sets the server port number for the next connection.   * The change in port only takes effect at the time of the   * next call to openConnection().   *   * @param port the port number.   */  final public void setPort(int port)  {    this.port = port;  }  /**   * @return the host name.   */  final public String getHost()  {    return host;  }  /**   * Sets the server host for the next connection.   * The change in host only takes effect at the time of the   * next call to openConnection().   *   * @param host the host name.   */  final public void setHost(String host)  {    this.host = host;  }  /**   * returns the client's description.   *   * @return the client's Inet address.   */  final public InetAddress getInetAddress()  {    return clientSocket.getInetAddress();  }// RUN METHOD -------------------------------------------------------  /**   * Waits for messages from the server. When each arrives,   * a call is made to <code>handleMessageFromServer()</code>.   * Not to be explicitly called.   */  final public void run()  {    connectionEstablished();    // The message from the server    Object msg;    // Loop waiting for data    try    {      while(!readyToStop)      {        // Get data from Server and send it to the handler        // The thread waits indefinitely at the following        // statement until something is received from the server        msg = input.readObject();        // Concrete subclasses do what they want with the        // msg by implementing the following method        handleMessageFromServer(msg);      }    }    catch (Exception exception)    {      if(!readyToStop)      {        try        {          closeAll();        }        catch (Exception ex) { }        connectionException(exception);      }    }    finally    {      clientReader = null;    }  }// METHODS DESIGNED TO BE OVERRIDDEN BY CONCRETE SUBCLASSES ---------  /**   * Hook method called after the connection has been closed.   * The default implementation does nothing. The method   * may be overriden by subclasses to perform special processing   * such as cleaning up and terminating, or attempting to   * reconnect.   */  protected void connectionClosed() {}  /**   * Hook method called each time an exception is thrown by the   * client's thread that is waiting for messages from the server.   * The method may be overridden by subclasses.   *   * @param exception the exception raised.   */  protected void connectionException(Exception exception) {}  /**   * Hook method called after a connection has been established.   * The default implementation does nothing.   * It may be overridden by subclasses to do anything they wish.   */  protected void connectionEstablished() {}  /**   * Handles a message sent from the server to this client.   * This MUST be implemented by subclasses, who should respond to   * messages.   *   * @param msg   the message sent.   */  protected abstract void handleMessageFromServer(Object msg);// METHODS TO BE USED FROM WITHIN THE FRAMEWORK ONLY ----------------  /**   * Closes all aspects of the connection to the server.   *   * @exception IOException if an I/O error occurs when closing.   */  private void closeAll() throws IOException  {    try    {      //Close the socket      if (clientSocket != null)        clientSocket.close();      //Close the output stream      if (output != null)        output.close();      //Close the input stream      if (input != null)        input.close();    }    finally    {      // Set the streams and the sockets to NULL no matter what      // Doing so allows, but does not require, any finalizers      // of these objects to reclaim system resources if and      // when they are garbage collected.      output = null;      input = null;      clientSocket = null;    }  }}// end of AbstractClient class

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品一区二区三区视频| 日本在线播放一区二区三区| 在线观看日韩av先锋影音电影院| 国产一区在线视频| 麻豆国产精品官网| 美女任你摸久久 | 成人性生交大片免费看视频在线| 蜜臀久久99精品久久久久宅男| 国产成人免费在线观看不卡| 福利一区二区在线观看| 成人高清免费观看| 91免费视频网| 91福利在线播放| 欧美另类久久久品| 在线播放91灌醉迷j高跟美女| 99久久久久久| 欧美日韩视频在线一区二区| 日韩欧美另类在线| 亚洲一区二区四区蜜桃| 亚洲综合图片区| 成人app软件下载大全免费| 精品国产乱码久久久久久浪潮 | 日韩色在线观看| 欧美激情在线一区二区三区| 久久精品人人爽人人爽| 中文字幕av一区二区三区免费看| 精品一二三四在线| 日韩欧美在线观看一区二区三区| 亚洲第一福利视频在线| 久久国产三级精品| 91丨porny丨最新| 国产精品久久久久久久久动漫 | 日本aⅴ免费视频一区二区三区| 久久99国产精品麻豆| 欧美理论片在线| 午夜在线电影亚洲一区| 色欧美日韩亚洲| 欧美不卡视频一区| 亚洲一区二区三区四区的 | 国产在线播放一区二区三区| 欧美一区二区视频观看视频| 国产精品伦一区二区三级视频| 亚洲综合色噜噜狠狠| 91麻豆文化传媒在线观看| 国产精品国产精品国产专区不片| 99久久久久免费精品国产 | 亚洲妇女屁股眼交7| 丁香婷婷综合五月| 中文字幕一区二区三区色视频| 午夜亚洲福利老司机| www.66久久| 久久综合视频网| 天天综合天天综合色| 91.麻豆视频| 国内精品写真在线观看| 在线综合+亚洲+欧美中文字幕| 天天做天天摸天天爽国产一区| 91精品国产色综合久久| 国产精品正在播放| 欧美一级黄色录像| 国产91丝袜在线播放九色| 综合激情成人伊人| 成人性生交大片| 夜夜夜精品看看| caoporn国产精品| 亚洲444eee在线观看| 久久青草国产手机看片福利盒子 | 久久精品人人做人人综合| 91一区在线观看| 自拍偷自拍亚洲精品播放| 精久久久久久久久久久| 4438x成人网最大色成网站| 亚洲大型综合色站| 欧美视频一区二区三区四区| 色综合久久66| 欧美日产在线观看| 一区二区三区在线视频免费观看| 欧美精品在线一区二区三区| 国产激情视频一区二区在线观看| 亚洲九九爱视频| 色综合久久99| 黑人精品欧美一区二区蜜桃| 亚洲免费av在线| 色婷婷久久综合| 国产美女视频91| 亚洲成人激情av| 最近日韩中文字幕| 久久久久久久综合色一本| 欧美精品久久99久久在免费线 | 精品一区二区影视| 亚洲女厕所小便bbb| 久久久久97国产精华液好用吗| 欧美色区777第一页| 成人app在线观看| 国精品**一区二区三区在线蜜桃| 夜色激情一区二区| 亚洲视频一二区| 日本一区二区在线不卡| 国产成人午夜高潮毛片| 人禽交欧美网站| 午夜电影一区二区三区| 亚洲色图另类专区| 中文字幕免费观看一区| 亚洲精品一区二区三区四区高清| 6080yy午夜一二三区久久| 色系网站成人免费| 99精品久久免费看蜜臀剧情介绍| 国产一区二区视频在线| 麻豆久久久久久| 蜜桃av一区二区三区电影| 天天色 色综合| 国产精品的网站| 日本一区二区视频在线| 日韩成人dvd| 伊人色综合久久天天人手人婷| 国产日本一区二区| 精品处破学生在线二十三| 日韩精品一区二| 日韩午夜在线影院| 日韩精品最新网址| 日韩精品在线看片z| 欧美一级久久久| 精品久久久久香蕉网| 久久综合久久综合久久综合| 精品国产a毛片| 久久久久国产精品麻豆ai换脸| 久久久www成人免费毛片麻豆| 精品国产乱码久久久久久夜甘婷婷| 精品久久久网站| 国产日韩欧美一区二区三区乱码| 国产精品你懂的| 亚洲精品欧美二区三区中文字幕| 亚洲综合激情网| 日韩av电影一区| 国产精品18久久久久| 成人h动漫精品一区二区| 91激情在线视频| 欧美疯狂做受xxxx富婆| 久久综合狠狠综合| 亚洲品质自拍视频| 日韩精品欧美成人高清一区二区| 亚洲精品在线免费观看视频| 久久久久高清精品| 亚洲伦在线观看| 免费精品视频在线| 成人av综合一区| 91麻豆精品国产| 欧美极品美女视频| 午夜婷婷国产麻豆精品| 国产精品综合二区| 欧美亚洲国产一区在线观看网站| 欧美一区二区三区免费视频| 日本一区二区三区免费乱视频| 亚洲精品欧美激情| 国产在线观看免费一区| 色哦色哦哦色天天综合| 精品国产成人在线影院| 亚洲美女屁股眼交3| 久久99久久久欧美国产| av一区二区三区在线| 欧美一区二区三区在线电影| 欧美国产一区二区| 麻豆精品一区二区av白丝在线| 成人a级免费电影| 欧美大片在线观看一区二区| 日韩理论电影院| 国产一区二区三区日韩| 欧美日韩精品一区二区天天拍小说 | 国产精品99久久久久久有的能看| 欧美综合亚洲图片综合区| ww亚洲ww在线观看国产| 午夜视频在线观看一区| 成人动漫一区二区三区| 精品福利一二区| 天堂蜜桃一区二区三区| 91首页免费视频| 国产亚洲综合在线| 麻豆91在线播放免费| 欧美色老头old∨ideo| 国产婷婷色一区二区三区在线| 日本在线播放一区二区三区| 在线一区二区观看| 中文字幕日韩一区| 国产v综合v亚洲欧| 欧美va亚洲va| 免费观看久久久4p| 7777精品伊人久久久大香线蕉的| 中文字幕色av一区二区三区| 国产成人日日夜夜| 亚洲精品一区二区三区四区高清| 天堂va蜜桃一区二区三区 | 成人午夜视频免费看| 久久只精品国产| 精品亚洲aⅴ乱码一区二区三区| 欧美日韩视频在线第一区 | 色94色欧美sute亚洲线路一久| 欧美激情资源网| 成人性生交大片免费看在线播放| 久久网这里都是精品| 国产一区二区免费在线|