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

📄 ppservices.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:


package com.sri.oaa2.pp;

import java.util.*;

public class ppServices{

  Hashtable mServerConnections = new Hashtable();
  Hashtable mClientsConnections = new Hashtable();

  public ppServices() {}

  public int ppSetServer(int inPortNumber, ppListener inListener) {
    ppServerConnection newServerConnection = new ppServerConnection(this, inPortNumber, inListener);
    newServerConnection.start();
    return newServerConnection.mSocketId;
  }

  public void ppSendData(int inSocketId, byte inData[], int inSize) {
    if (mServerConnections.containsKey(new Integer(inSocketId))) {
       ppServerConnection localServerConnection = (ppServerConnection)(mServerConnections.get(new Integer(inSocketId)));
       localServerConnection.sendData(inData, inSize);
    }else
    if (mClientsConnections.containsKey(new Integer(inSocketId))) {
       ppLocalClientConnection localClientConnection = (ppLocalClientConnection)(mClientsConnections.get(new Integer(inSocketId)));
       localClientConnection.sendData(inData, inSize);
    }
  }

  public int ppSetClient(String inHostName, int inPortNumber, ppListener inListener) {
    return ppSetClient(inHostName, inPortNumber, Thread.NORM_PRIORITY, inListener);
  }

  public int ppSetClient(String inHostName, int inPortNumber, int inPriority, ppListener inListener)  {
    ppLocalClientConnection newClientConnection = new ppLocalClientConnection(this, inHostName, inPortNumber, inPriority, inListener);
    newClientConnection.start();
    return newClientConnection.mSocketId;
  }

  public void ppDisconnect(int inSocketId) {
    if (mServerConnections.containsKey(new Integer(inSocketId))) {
       ppServerConnection localServerConnection = (ppServerConnection)(mServerConnections.get(new Integer(inSocketId)));
       localServerConnection.disconnect();
    }else
    if (mClientsConnections.containsKey(new Integer(inSocketId))) {
       ppLocalClientConnection localClientConnection = (ppLocalClientConnection)(mClientsConnections.get(new Integer(inSocketId)));
       localClientConnection.disconnect();
    }
  }

  public boolean ppIsClient(int inSocketId) {
    // First, it can be a local client
    if (mClientsConnections.containsKey(new Integer(inSocketId)))
      return true;
    // Then looks through clients of all servers
    for (Enumeration enum = mServerConnections.elements(); enum.hasMoreElements();) {
      ppServerConnection currentServer = (ppServerConnection)enum.nextElement();
      if (currentServer.mClients.containsKey(new Integer(inSocketId)))
        return true;
    }
    return false;
  }

  public boolean ppIsServer(int inSocketId) {
    return mServerConnections.containsKey(new Integer(inSocketId));
  }

}

⌨️ 快捷键说明

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