示例#1
1
  @Override
  public void run() {
    // TODO Auto-generated method stub
    if (localAddress == null) {
      Log.w(LOGTAG, "no network address avalibe to listen");
      return;
    }
    ServerSocket Server;
    try {

      Server = new ServerSocket(port, 10, localAddress);

      System.out.println(
          "TCPServer Waiting for client on " + localAddress.getHostAddress() + ": " + port);

      while (true) {
        Socket connected = Server.accept();
        (new HttpServer(connected)).start();
      }
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  /**
   * Constructor. Creates a datagram send socket and connects it to the Ganglia hypertable extension
   * listen port. Initializes mPrefix to "ht." + <code>component</code> + ".".
   *
   * @param component Hypertable component ("fsbroker", "hyperspace, "master", "rangeserver", or
   *     "thriftbroker")
   * @param props Configuration properties
   */
  public MetricsCollectorGanglia(String component, Properties props) {
    mPrefix = "ht." + component + ".";

    String str = props.getProperty("Hypertable.Metrics.Ganglia.Port", "15860");
    mPort = Integer.parseInt(str);

    str = props.getProperty("Hypertable.Metrics.Ganglia.Disabled");
    if (str != null && str.equalsIgnoreCase("true")) mDisabled = true;

    try {
      mAddr = InetAddress.getByName("localhost");
    } catch (UnknownHostException e) {
      System.out.println("UnknownHostException : 'localhost'");
      e.printStackTrace();
      System.exit(-1);
    }

    try {
      mSocket = new DatagramSocket();
    } catch (SocketException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    mSocket.connect(mAddr, mPort);
    mConnected = true;
  }
示例#3
0
  public boolean setTestSenderRule(
      int testTag, int returnTag, int testGeneratorSrcIP, int testSrcIP) {
    Flow flow = new Flow();
    Match match = new Match();
    List<Action> actions = new ArrayList<Action>();
    try {
      System.out.println(
          "TestTag:"
              + testTag
              + " returnTag:"
              + returnTag
              + " testSrcIP:"
              + FTUtil.IPAddressStringFromInt(testSrcIP)
              + " testGenIP:"
              + FTUtil.IPAddressStringFromInt(testGeneratorSrcIP));
    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    match.setField(MatchType.DL_TYPE, (short) 0x0800);
    match.setField(MatchType.NW_TOS, (byte) (testTag / 4));
    try {
      actions.add(new SetNwTos((byte) 0));
      actions.add(new SetNwSrc(FTUtil.InetAddressFromInt(testSrcIP)));
      actions.add(new Loopback());
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    flow.setMatch(match);
    flow.setActions(actions);
    flow.setPriority((short) 200);
    this.addFlowRule(flow);

    flow = new Flow();
    match = new Match();
    actions = new ArrayList<Action>();
    try {
      match.setField(MatchType.DL_TYPE, (short) 0x0800);
      match.setField(MatchType.NW_DST, (FTUtil.InetAddressFromInt(testSrcIP)));
      actions.add(new SetNwTos((byte) returnTag));
      actions.add(new SetNwDst(FTUtil.InetAddressFromInt(testGeneratorSrcIP)));
      actions.add(new Loopback());
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    flow.setMatch(match);
    flow.setActions(actions);
    flow.setPriority((short) 200);
    this.addFlowRule(flow);

    return true;
  }
  public Server() {
    try {
      ServerSocket ss = new ServerSocket(SERVER_PORT);

      Socket s = ss.accept();

      InputStream is = s.getInputStream();
      OutputStream out = s.getOutputStream();
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);

      String sss = br.readLine();
      System.out.println(sss);

      PrintWriter pw = new PrintWriter(out);
      pw.print("hello,我是服务器。");

      pw.close();
      br.close();
      isr.close();
      out.close();
      is.close();
      s.close();
      ss.close();
    } catch (UnknownHostException ue) {
      ue.printStackTrace();
    } catch (IOException oe) {
      oe.printStackTrace();
    }
  }
示例#5
0
 /**
  * 下载文件
  *
  * @param params 请求参数
  * @param filepath 保存路径
  */
 public static File downloadFile(RequestParams params, String filepath) throws TaskException {
   // 设置断点续传
   params.setAutoResume(true);
   params.setSaveFilePath(filepath);
   try {
     return x.http().getSync(params, File.class);
   } catch (SocketTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (ConnectTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (UnknownHostException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (IOException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (Throwable throwable) {
     TaskException taskException = null;
     if (throwable.getCause() instanceof TaskException) {
       taskException = (TaskException) throwable.getCause();
     } else if (throwable instanceof TaskException) {
       taskException = (TaskException) throwable;
     }
     if (taskException != null) {
       throw taskException;
     }
     throw new TaskException(
         "", TextUtils.isEmpty(throwable.getMessage()) ? "服务器错误" : throwable.getMessage());
   }
 }
示例#6
0
 public static void createBoltIdentifyingFiles(TopologyContext topologyContext) {
   String componentName = topologyContext.getThisComponentId();
   Long ts = System.currentTimeMillis();
   String fileName = "bolt-" + ts + "-" + componentName + ".log";
   File file =
       new File(
           in.dream_lab.stream.eventgen.utils.GlobalConstants.defaultBoltDirectory + fileName);
   try {
     FileWriter fw = new FileWriter(file);
     BufferedWriter bw = new BufferedWriter(fw);
     String rowString =
         InetAddress.getLocalHost().getHostName()
             + ","
             + Thread.currentThread().getName()
             + ","
             + componentName
             + ","
             + ts;
     bw.write(rowString);
     bw.flush();
     bw.close();
   } catch (UnknownHostException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#7
0
  protected Void doInBackground(Door... Void) {
    try {
      Log.v("", "Opening Socket");
      Socket socket = new Socket("192.168.163.37", 8080);
      // Socket socket = new Socket("192.168.171.1", 8080);
      Log.v("", "Opened Socket");

      try {
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        out.write("garageUp");
        out.flush();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      Log.v("", "Closing Socket");
      socket.close();

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
示例#8
0
 static {
   try {
     hostname = InetAddress.getLocalHost().getHostName();
   } catch (UnknownHostException e) {
     e.printStackTrace();
   }
 }
  /**
   * Tries to start a server on the specified port.
   *
   * @param host - host name (IP) to use
   * @param port - port to use for opened socket
   */
  private void init(String host, int port) {
    if (host != null) {
      this.host = host;
    } else {
      try {
        this.host = InetAddress.getLocalHost().getHostAddress();
      } catch (UnknownHostException xcp) {
        xcp.printStackTrace();
        this.host = null;
      }
    }

    try {
      serverSocket = new ServerSocket(port);
    } catch (IOException xcp) {
      handleFailureToCreateServerSocket(port, xcp);
      return;
    }

    // Get port being used for server socket
    this.port = serverSocket.getLocalPort();

    // Create a server thread and start it listening
    Runnable serverConnectionDaemon = new ServerConnectionDaemon();
    ThreadTools.startAsDaemon(serverConnectionDaemon, "Data Object Server Conn Daemon");

    printIfDebug(
        ".init: comm server started listening on:\n"
            + "\thost = "
            + this.host
            + "\n\tport = "
            + this.port);
  }
示例#10
0
文件: Top.java 项目: pan-rui/yihao
 private static void addResolve(String host, String ip) {
   try {
     MAPPINGS.put(host, new InetAddress[] {InetAddress.getByName(ip)});
   } catch (UnknownHostException e) {
     e.printStackTrace();
   }
 }
  /**
   * This method created a socket and a packet. It is performed only once in
   *
   * <p>the constructor of JoyActivity.
   *
   * <p>Indeed, two objects are required for UDP communication, a socket and a
   *
   * <p>packet as respective class DatagramSocket and DatagramPacket (classes
   *
   * <p>available in the Android libraries).
   *
   * @param ComandeUDP start command
   * @param port The Port to use
   * @param host The Address IP target
   */
  public DatagramSocket CreationSocketPacket(String ComandeUDP, int port, String host) {
    buffer = new byte[512];

    try { // TRY CREATION SOCKET
      udp_socket = new DatagramSocket();

    } catch (SocketException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    try { // INSERTION TRAME
      buffer = ComandeUDP.concat("\r").getBytes("ASCII");

    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try { // INSERTION ADRESSE
      adresse = InetAddress.getByName(host);
    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    udp_packet = new DatagramPacket(buffer, buffer.length, adresse, port);
    return udp_socket;
  }
示例#12
0
 public int SendLoginInfoToServer(Object o) {
   int b = 2; // 1:密码正确,2:密码错误 3:已经在线
   try {
     s = new Socket("127.0.0.1", 9999);
     ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
     oos.writeObject(o);
     ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
     Message ms = (Message) ois.readObject();
     // 这里就是验证用户登录的地方
     if (ms.getMesType().equals("1")) {
       // 就创建一个该qq号和服务器端保持通讯连接的线程
       ClientConServerThread ccst = new ClientConServerThread(s);
       // 启动该通讯线程
       ccst.start();
       ManageClientConServerThread.addClientConServerThread(((User) o).getUserId(), ccst);
       b = 1;
     } else if (ms.getMesType().equals(MessageType.message_online)) b = 3;
   } catch (UnknownHostException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   }
   return b;
 }
示例#13
0
  private void getChunkProcess() {
    Chunk ch = null;
    Boolean found = false;
    for (int i = 0; i < Main.getDatabase().getChunksSize(); i++) {
      ch = Main.getDatabase().getChunk(i);
      if (ch.getFileId().equals(header.get(2))
          && (ch.getChunkNo() == Integer.parseInt(header.get(3)))) {
        found = true;
        break;
      }
    }

    if (found) {
      FileManager chunk = new FileManager(header.get(2), 0, true);
      chunk.readChunk(Integer.parseInt(header.get(3)), Main.getDatabase().getUsername());

      String ip = "";
      try {
        ip = InetAddress.getLocalHost().toString().split("/")[1];
      } catch (UnknownHostException e) {
        e.printStackTrace();
      }

      int tcp_port = Main.getTCPport();
      String message =
          "ME "
              + header.get(2)
              + " "
              + header.get(3)
              + " "
              + ip
              + " "
              + tcp_port
              + Main.getCRLF()
              + Main.getCRLF();

      byte[] msg = message.getBytes(StandardCharsets.ISO_8859_1);
      Main.getRestore().send(msg);
      Main.getLogger().log("Received: " + message);

      try {
        TCPCommunicator tcpSocket = new TCPCommunicator(ip, tcp_port, true);
        String chunkMsg =
            "CHUNK " + header.get(2) + " " + header.get(3) + Main.getCRLF() + Main.getCRLF();

        Main.getLogger().log("Sent: " + chunkMsg);

        byte[] chunkBytes =
            Main.appendArray(chunkMsg.getBytes(StandardCharsets.ISO_8859_1), chunk.getChunkData());
        tcpSocket.send(chunkBytes);

        tcpSocket.close();

      } catch (SocketTimeoutException e) {
        System.out.println("I was not the chosen one!");
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
示例#14
0
 public void createConnection() {
   try {
     Log.v("1111", "1111");
     socket2 = new Socket();
     Log.v("2222", "2222");
     socket2.connect(new InetSocketAddress(ip, port), 15 * 1000);
     Log.v("3333", "3333");
   } catch (UnknownHostException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     if (socket2 != null) {
       try {
         socket2.close();
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     if (socket2 != null) {
       try {
         socket2.close();
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   } finally {
   }
 }
示例#15
0
  @Override
  public void run() {
    while (true) {
      try {
        // Prepare the input stream
        in = new BufferedReader(new InputStreamReader(serverSocket.getInputStream()));

        // Block until the server sends you something
        String s = in.readLine();
        // Formulate a ServerResponse object from the server's response
        ServerResponse sr = new ServerResponse(new JSONObject(s));
        // Call the appropriate method.
        testClient.synchronizeResponse(sr);

      } catch (UnknownHostException e) {
        e.printStackTrace();
        break;
      } catch (IOException e) {
        e.printStackTrace();
        break;
      } catch (ServerResponseException e) {
        e.printStackTrace();
        break;
      } catch (JSONException e) {
        e.printStackTrace();
        break;
      }
    }
  }
示例#16
0
  // 如果返回的信息是friendsinfo表示成功 该信息还包含了friend的信息(id,ip,online),将其解析并放在friends集合中
  // 然后 开启 主界面(id,ip,与服务器的连接插座,好友列表)
  // 返回信息为否时 显示 错误信息
  public void analyseResult(String result) {
    String[] command = result.split("#");
    if (command[0].equals("friendsinfo")) {
      friends = new ArrayList<Friend>();
      for (int i = 1; i < command.length; i++) {
        String[] friendinfo = command[i].split("@");
        friends.add(
            new Friend(
                tid.getText().trim(),
                friendinfo[0],
                friendinfo[1],
                friendinfo[2].equals("true") ? true : false));
      }
      try {

        new Mainui(tid.getText().trim(), InetAddress.getLocalHost().getHostAddress(), s, friends);
      } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      this.dispose();
    } else if (command[0].equals("false")) {
      JOptionPane.showMessageDialog(this, "无此用户或密码错误");
    }
  }
示例#17
0
 public static <T> T doPostSync(RequestParams params, Class<T> responseCls) throws TaskException {
   try {
     return x.http().postSync(params, responseCls);
   } catch (SocketTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (ConnectTimeoutException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (UnknownHostException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (IOException e) {
     e.printStackTrace();
     throw new TaskException(TaskException.TaskError.timeout.toString());
   } catch (Throwable throwable) {
     TaskException taskException = null;
     if (throwable.getCause() instanceof TaskException) {
       taskException = (TaskException) throwable.getCause();
     } else if (throwable instanceof TaskException) {
       taskException = (TaskException) throwable;
     }
     if (taskException != null) {
       throw taskException;
     }
     throw new TaskException(
         "", TextUtils.isEmpty(throwable.getMessage()) ? "服务器错误" : throwable.getMessage());
   }
 }
示例#18
0
  /**
   * Name: getIPAddress Description: Iterates through the device's IPAddresses and returns first
   * non-local IPAddress
   *
   * @return String containing the first non-local IPAddress of the device.
   */
  public InetAddress getIPAddress() {

    try {
      for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
          en.hasMoreElements(); ) {

        NetworkInterface networkInterface = en.nextElement();

        for (Enumeration<InetAddress> enumIpAddr = networkInterface.getInetAddresses();
            enumIpAddr.hasMoreElements(); ) {

          InetAddress inetAddress = enumIpAddr.nextElement();

          if (!inetAddress.isLoopbackAddress()
              && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) {
            return inetAddress;
          }
        }
      }
      return InetAddress.getByName("127.0.0.1");

    } catch (SocketException ex) {
      ex.printStackTrace();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
    return null;
  }
示例#19
0
  void sendMessage(String msg) {
    try {
      ObjectOutputStream outputToAnotherObject = null;
      ObjectInputStream inputFromAnotherObject = null;
      Thread.sleep(500);

      // Send 5 messages to the Server

      // write to socket using ObjectOutputStream
      outputToAnotherObject =
          new ObjectOutputStream(getRoverSocket().getNewSocket().getOutputStream());

      System.out.println("=================================================");
      System.out.println("RAD Client: Sending request to Socket Server");
      System.out.println("=================================================");

      outputToAnotherObject.writeObject(msg);

      // read the server response message
      inputFromAnotherObject = new ObjectInputStream(getRoverSocket().getSocket().getInputStream());
      String message = (String) inputFromAnotherObject.readObject();
      System.out.println("RAD Client received: " + message.toUpperCase());

      // close resources
      inputFromAnotherObject.close();
      outputToAnotherObject.close();
      Thread.sleep(100);

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (Exception error) {
      System.out.println("Client: Error:" + error.getMessage());
    }
  }
示例#20
0
  public static String getLocalAddress() {
    try {
      // 遍历网卡,查找一个非回路ip地址并返回
      Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
      InetAddress ipv6Address = null;
      while (enumeration.hasMoreElements()) {
        final NetworkInterface networkInterface = enumeration.nextElement();
        final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
        while (en.hasMoreElements()) {
          final InetAddress address = en.nextElement();
          if (!address.isLoopbackAddress()) {
            if (address instanceof Inet6Address) {
              ipv6Address = address;
            } else {
              // 优先使用ipv4
              return normalizeHostAddress(address);
            }
          }
        }
      }
      // 没有ipv4,再使用ipv6
      if (ipv6Address != null) {
        return normalizeHostAddress(ipv6Address);
      }
      final InetAddress localHost = InetAddress.getLocalHost();
      return normalizeHostAddress(localHost);
    } catch (SocketException e) {
      e.printStackTrace();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }

    return null;
  }
  private void getTweetWithRTCountGreaterThan(int gt) {

    Mongo mongo = null;
    try {
      mongo = new Mongo(MONGO_DB_HOST, MONGO_DB_PORT);
      DB db = mongo.getDB(MONGO_DB_NAME);
      DBCollection collection = db.getCollection(MONGO_DB_COLLECTION);

      DBCursor cursor = collection.find(new BasicDBObject("rTCount", new BasicDBObject("$gt", gt)));

      DBObject dbObject;

      System.out.println("\n\n========================================");
      System.out.println("Displaying Tweet with RTCount > " + gt);

      while (cursor.hasNext()) {
        dbObject = cursor.next();
        System.out.println(
            "user "
                + dbObject.get("user")
                + "tweet "
                + dbObject.get("tweet")
                + " RTCount "
                + dbObject.get("rTCount"));
      }

      System.out.println("========================================\n\n");

    } catch (UnknownHostException e) {
      e.printStackTrace();
    } finally {
      if (mongo != null) mongo.close();
    }
  }
  public static void main(String[] args) {
    MongoClient mongo = null;

    try {

      SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

      mongo = new MongoClient("localhost");

      Morphia morphia = new Morphia();
      GalerieDao daoGalerie = new GalerieDao(mongo, morphia);
      ExpositionDao dao = new ExpositionDao(mongo, morphia);
      List<Exposition> expos = new ArrayList<>();
      List<Galerie> galeris = new ArrayList<>();
      // expos = dao.findParCategorie();

      // galeris = daoGalerie.find().asList();
      // expos = dao.findProximite(2.33,48.859,0.3/6371);
      expos = dao.findParArtiste("Michaël F.");

      for (Exposition ex : expos) {
        System.out.println(ex);
      }
      System.out.println(expos.size());
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void event(WatchEvent.Kind kind, Path path) {
    // System.out.println("Log event");

    File file = new File(path.toString());
    String ip = "0.0.0.0", owner = "unknown";
    try {
      ip = Inet4Address.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
    try {
      FileOwnerAttributeView ownerAttributeView =
          Files.getFileAttributeView(path, FileOwnerAttributeView.class);
      owner = ownerAttributeView.getOwner().getName();
    } catch (IOException e) {
      e.printStackTrace();
    }

    String entry =
        String.format(
            "[%s] \"%s\" copied on \"%s\" by \"%s\"\n",
            new SimpleDateFormat("dd/MMM/YYYY HH:mm:ss").format(new Date()),
            path.toString(),
            ip,
            owner);

    try {
      Files.write(Paths.get(logFile), entry.getBytes(), StandardOpenOption.APPEND);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#24
0
  // 获得IP地址
  public static String getIpAddr(HttpServletRequest request) {
    String ipAddress = null;
    ipAddress = request.getHeader("x-forwarded-for");
    if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getHeader("Proxy-Client-IP");
    }
    if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
      ipAddress = request.getRemoteAddr();
      if (ipAddress.equals("127.0.0.1")) {
        // 根据网卡取本机配置的IP
        InetAddress inet = null;
        try {
          inet = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
          e.printStackTrace();
        }
        ipAddress = inet.getHostAddress();
      }
    }

    // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
    if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length()
      // = 15
      if (ipAddress.indexOf(",") > 0) {
        ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
      }
    }
    return ipAddress;
  }
示例#25
0
  public static void main(String[] args) {
    try {
      ServerSocket socket = new ServerSocket(8606, 50, InetAddress.getByName("localhost"));
      Socket client = socket.accept();

      OutputStream out = client.getOutputStream();
      InputStream in = client.getInputStream();

      DataOutputStream dout = new DataOutputStream(out);
      DataInputStream din = new DataInputStream(in);

      String line = null;

      while (true) {
        line = din.readUTF();
        System.out.println(line);
        dout.writeUTF(line);
      }

    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#26
0
 @Override
 public void run() {
   Socket clientSocket = null;
   PrintWriter out = null;
   try {
     Debug.log(ReportServlet.SERVLET, "[NotifyUsers]: notifying user: "******";" + latitude + ";" + reportID);
     Debug.log(ReportServlet.SERVLET, "[NotifyUsers]: end notify user: " + clientAddress);
   } catch (UnknownHostException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     if (out != null) {
       out.close();
     }
     if (clientSocket != null) {
       try {
         clientSocket.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
 }
示例#27
0
  /**
   * Funcion que permite publicar la url del servicio Web
   *
   * @param arg
   */
  public static void main(String arg[]) {
    String ip = "";
    String puerto = "";

    try {
      ResourceBundle rb = ResourceBundle.getBundle("co.com.codesoftware.properties.baseProperties");
      String valida = rb.getString("IP_DINAMICA");

      if ("SI".equalsIgnoreCase(valida)) {
        ip = rb.getString("IP_FIJA");
      } else {
        ip = InetAddress.getLocalHost().getHostAddress();
      }
      puerto = rb.getString("PUERTO");
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    System.out.println("Este es la ip: " + ip);
    Endpoint.publish("http://" + ip + ":" + puerto + "/WS/server", new SAFWS());
    System.out.println(
        "Servicos desplegados en la siguiente direccion: \n\n\n"
            + "http://"
            + ip
            + ":"
            + puerto
            + "/WS/server/SAFWS?wsdl");
  }
示例#28
0
 @Override
 public void configurePrefilledUserRatings(
     String username,
     String repoName,
     String primaryKey,
     String itemTable,
     String tableName,
     String userIdCol,
     String itemIdCol,
     String userRatingCol) {
   try {
     DatahubDataModel model = new DatahubDataModel();
     model.configurePrefilledUserRatings(
         username,
         repoName,
         primaryKey,
         itemTable,
         tableName,
         userIdCol,
         itemIdCol,
         userRatingCol);
   } catch (UnknownHostException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  @Override
  protected Inet6Address ipAddressRandomizer(InetAddress realAddress) {
    byte[] addr = {
      realAddress.getAddress()[0],
      realAddress.getAddress()[1],
      realAddress.getAddress()[2],
      realAddress.getAddress()[3],
      realAddress.getAddress()[4],
      realAddress.getAddress()[5],
      realAddress.getAddress()[6],
      realAddress.getAddress()[7],
      realAddress.getAddress()[8],
      realAddress.getAddress()[9],
      realAddress.getAddress()[10],
      realAddress.getAddress()[11],
      (byte) 0,
      (byte) 0,
      (byte) 0,
      (byte) 0
    };

    Inet6Address fakeV4 = null;
    try {
      fakeV4 = (Inet6Address) Inet6Address.getByAddress(addr);
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }

    return fakeV4;
  }
  /**
   * Client application will be started with the main() of the {@link ClientServicesStarter}
   *
   * @param args the parameter which is passed to the main()
   */
  public static void startClient() {

    try {
      props.put("client.ip", InetAddress.getLocalHost().getHostAddress());

    } catch (IOException e) {
      e.printStackTrace();
    }

    ClientServicesStarter client = new ClientServicesStarter();
    RemoteNodeRegistration nodeRegister = (RemoteNodeRegistration) client.startProxy();

    try {
      if (nodeRegister != null) {
        String SERVER_IP = nodeRegister.registerNode(InetAddress.getLocalHost().getHostAddress());
        ClientServicesStarter.serverName(SERVER_IP);
        client.loadNode();
      } else {
        log.debug("Server at " + props.getProperty("server.ip") + " not found");
        System.exit(1);
      }

    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
  }