public byte[] getRAddr() { try { InetAddress addr = InetAddress.getByName(host); return addr.getAddress(); } catch (UnknownHostException e) { System.err.println("NCCPConnection::getRAddr Don't know about host: "); return null; } }
public AppFrame() { super(); GlobalData.oFrame = this; this.setSize(this.width, this.height); this.toolkit = Toolkit.getDefaultToolkit(); Dimension w = toolkit.getScreenSize(); int fx = (int) w.getWidth(); int fy = (int) w.getHeight(); int wx = (fx - this.width) / 2; int wy = (fy - this.getHeight()) / 2; setLocation(wx, wy); this.tracker = new MediaTracker(this); String sHost = ""; try { localAddr = InetAddress.getLocalHost(); if (localAddr.isLoopbackAddress()) { localAddr = LinuxInetAddress.getLocalHost(); } sHost = localAddr.getHostAddress(); } catch (UnknownHostException ex) { sHost = "你的IP地址错误"; } // this.textLines[0] = "服务器正在运行."; this.textLines[1] = ""; this.textLines[2] = "你的IP地址: " + sHost; this.textLines[3] = ""; this.textLines[4] = "请打开你的手机客户端"; this.textLines[5] = ""; this.textLines[6] = "输入屏幕上显示的IP地址."; // try { URL fileURL = this.getClass().getProtectionDomain().getCodeSource().getLocation(); String sBase = fileURL.toString(); if ("jar".equals(sBase.substring(sBase.length() - 3, sBase.length()))) { jar = new JarFile(new File(fileURL.toURI())); } else { basePath = System.getProperty("user.dir") + "\\res\\"; } } catch (Exception ex) { this.textLines[1] = "exception: " + ex.toString(); } }
Target(String host) { add = host; try { address = new InetSocketAddress(InetAddress.getByName(host), port); } catch (IOException x) { failure = x; } }
public Jframe(String args[]) { super(); try { sign.signlink.startpriv(InetAddress.getByName(server)); initUI(); } catch (Exception ex) { ex.printStackTrace(); } }
// constructor public GameClient_(JFrame oldWindow, MultiPlayerMenuWindow multiPlayerMenu, boolean localHost) { m_MultiPlayerMenu = multiPlayerMenu; m_OldWindow = oldWindow; try { m_IP = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { System.err.println(e); } m_Port = 8000; }
public LoginBox() { super("VnmrJ Login"); dolayout("", "", ""); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); // setVast(); DisplayOptions.addChangeListener(this); try { InetAddress inetAddress = InetAddress.getLocalHost(); m_strHostname = inetAddress.getHostName(); } catch (Exception e) { m_strHostname = "localhost"; } VNMRFrame vnmrFrame = VNMRFrame.getVNMRFrame(); Dimension size = vnmrFrame.getSize(); position = vnmrFrame.getLocationOnScreen(); AppIF appIF = Util.getAppIF(); int h = appIF.statusBar.getSize().height; width = size.width; height = size.height - h; // Allow resizing and use the previous size and position // To stop resizing, use setResizable(false); readPersistence(); // setSize(width, height); // setLocation(position); // setResizable(false); setBackgroundColor(Util.getBgColor()); m_trayTimer = new javax.swing.Timer( 6000, new ActionListener() { public void actionPerformed(ActionEvent e) { setTrays(); } }); }
// constructor public GameClient_(JFrame oldWindow, MultiPlayerMenuWindow multiPlayerMenu) { m_MultiPlayerMenu = multiPlayerMenu; m_OldWindow = oldWindow; try { m_IP = InetAddress.getLocalHost().getHostAddress(); JOptionPane.showMessageDialog(oldWindow, "Server's IP: " + m_IP); } catch (UnknownHostException e) { System.err.println(e); } m_Port = 8000; }
@Override public void run() { try { // Create a server socket ServerSocket serverSocket = new ServerSocket(8000); textArea.append("TCP connection listener started at " + new Date() + '\n'); while (true) { // Listen for a new connection request Socket socket = serverSocket.accept(); // Display the client number textArea.append( "Starting thread for TCP client " + clientNo + " at " + new Date() + '\n'); // Find the client's host name, and IP address InetAddress inetAddress = socket.getInetAddress(); textArea.append( "Client " + clientNo + "'s host name is " + inetAddress.getHostName() + "\n"); textArea.append( "Client " + clientNo + "'s IP Address is " + inetAddress.getHostAddress() + "\n"); // Create a new thread for the TCP connection HandleTCPClient task = new HandleTCPClient(socket); // Start the new thread new Thread(task).start(); // Increment clientNo clientNo++; } } catch (IOException ex) { System.err.println(ex); } }
public void actionPerformed(ActionEvent e) { String one = new String("hello"); String two = new String("world"); try { theSocket = new Socket(InetAddress.getByName("52.91.187.211"), 2000); socketOutput = theSocket.getOutputStream(); socketInput = theSocket.getInputStream(); theConnection = new ConnectionThread(); theConnection.start(); System.out.println("connect"); connectButton.setEnabled(false); } catch (Exception ex) { System.out.println(ex.toString()); } }
// {{{ EditServer constructor EditServer(String portFile) { super("jEdit server daemon [" + portFile + "]"); setDaemon(true); this.portFile = portFile; try { // On Unix, set permissions of port file to rw-------, // so that on broken Unices which give everyone read // access to user home dirs, people can't see your // port file (and hence send arbitriary BeanShell code // your way. Nasty.) if (OperatingSystem.isUnix()) { new File(portFile).createNewFile(); FileVFS.setPermissions(portFile, 0600); } // Bind to any port on localhost; accept 2 simultaneous // connection attempts before rejecting connections socket = new ServerSocket(0, 2, InetAddress.getByName("127.0.0.1")); authKey = new Random().nextInt(Integer.MAX_VALUE); int port = socket.getLocalPort(); FileWriter out = new FileWriter(portFile); try { out.write("b\n"); out.write(String.valueOf(port)); out.write("\n"); out.write(String.valueOf(authKey)); out.write("\n"); } finally { out.close(); } ok = true; Log.log(Log.DEBUG, this, "jEdit server started on port " + socket.getLocalPort()); Log.log(Log.DEBUG, this, "Authorization key is " + authKey); } catch (IOException io) { /* on some Windows versions, connections to localhost * fail if the network is not running. To avoid * confusing newbies with weird error messages, log * errors that occur while starting the server * as NOTICE, not ERROR */ Log.log(Log.NOTICE, this, io); } } // }}}
public EchoAWT() throws UnknownHostException { super("채팅 프로그램"); // 각종 정의 h = new JPanel(new GridLayout(2, 3)); m = new JPanel(new BorderLayout()); f = new JPanel(new BorderLayout()); s = new JPanel(new BorderLayout()); login = new JPanel(new BorderLayout()); // name = new JLabel(" 사용자 이름 "); name = new JLabel(" 메세지 입력 "); jta = new JTextArea(); // clientList = new JTextArea(0, 10); clientList = new JList(); jsp = new JScrollPane(jta); list = new JScrollPane(clientList); jtf = new JTextField("입력하세요."); hi = new JTextField("HOST IP 입력"); pi = new JTextField("PORT 입력"); localport = new JTextField("원하는 PORT 입력"); lid = new JTextField("ID를 입력하세요."); lpw = new JTextField("PW를 입력하세요."); serveropen = new JButton("서버 오픈"); textin = new JButton("입력"); clientin = new JButton("서버 접속"); conf = new JButton("로그인"); join = new JButton("회원가입"); addr = InetAddress.getLocalHost(); // 사용자 해상도 및 창 크기 설정 및 가져오기. Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); setSize(500, 500); Dimension d = getSize(); // 각종 버튼 및 텍스트 필드 리스너 jtf.addActionListener(this); hi.addActionListener(this); pi.addActionListener(this); localport.addActionListener(this); lid.addActionListener(this); lpw.addActionListener(this); conf.addActionListener(this); join.addActionListener(this); serveropen.addActionListener(this); clientin.addActionListener(this); textin.addActionListener(this); jtf.addFocusListener(this); hi.addFocusListener(this); pi.addFocusListener(this); localport.addFocusListener(this); lid.addFocusListener(this); lpw.addFocusListener(this); // 서버 접속 h.add(hi); h.add(pi); h.add(clientin); // 서버 생성 h.add(new JLabel("IP : " + addr.getHostAddress(), (int) CENTER_ALIGNMENT)); h.add(localport); h.add(serveropen); // 채팅글창 글 작성 막기 jta.setEditable(false); // 접속자 리스트 width 제한 clientList.setFixedCellWidth(d.width / 3); // 입력 창 f.add(name, "West"); f.add(jtf, "Center"); f.add(textin, "East"); // 접속자 확인창 s.add(new JLabel("접속자", (int) CENTER_ALIGNMENT), "North"); s.add(list, "Center"); // clientList.setEditable(false); // 메인 창 m.add(jsp, "Center"); m.add(s, "East"); // 프레임 설정 add(h, "North"); add(m, "Center"); add(f, "South"); // 로그인 다이얼로그 jd = new JDialog(); jd.setTitle("채팅 로그인"); jd.add(login); jd.setSize(200, 200); Dimension dd = jd.getSize(); jd.setLocation(screenSize.width / 2 - (dd.width / 2), screenSize.height / 2 - (dd.height / 2)); jd.setVisible(true); // 로그인창 JPanel lm = new JPanel(new GridLayout(4, 1)); lm.add(lid); lm.add(new Label()); lm.add(lpw); lm.add(new Label()); JPanel bt = new JPanel(); bt.add(conf); bt.add(join); login.add(new Label(), "North"); login.add(new Label(), "West"); login.add(new Label(), "East"); login.add(lm, "Center"); login.add(bt, "South"); // 창의 위치, 보임, EXIT 단추 활성화. setLocation(screenSize.width / 2 - (d.width / 2), screenSize.height / 2 - (d.height / 2)); setVisible(false); setDefaultCloseOperation(EXIT_ON_CLOSE); }
public static IUmenu mainAE() { PerfilesBD coleccion = new PerfilesBD(); final PerfilesBD perfilesDB = coleccion; String ip = ""; try { ip = InetAddress.getLocalHost().getHostAddress(); } catch (Exception exp) { } ipServer = ip; final String ipDef = ip; if (!coleccion.estaMontadoServidor()) { new Thread() { public void run() { try { Servidor servidor = new Servidor(); servidor.ejecutarServidor(); } catch (Exception e) { System.out.println(e); } } }.start(); /*new Thread() { public void run() { try { ServidorChat servidorChat = new ServidorChat(); servidorChat.ejecutarServidor(); } catch (Exception e) { System.out.println(e); } } }.start();*/ new Thread() { public void run() { try { ClienteAdm clienteAdm = new ClienteAdm(ipDef); } catch (Exception e) { System.out.println(e); } } }.start(); } String hostOut = coleccion.getHostServidor(); IUmenu a = new IUmenu(hostOut); a.setBounds(120, 70, 800, 600); a.setUndecorated(true); a.getRootPane().setWindowDecorationStyle(0); a.setDefaultCloseOperation(a.DO_NOTHING_ON_CLOSE); a.setResizable(false); a.setVisible(true); menu = a; return a; }
public void actionPerformed(ActionEvent e) { if (e.getSource() == Connect) { if (nbr < 3) { if (nom.getText().length() == 0 || pwd.getPassword().length == 0 || jTextField1.getText().length() == 0) { JOptionPane.showMessageDialog( null, "Vous devez donner votre pseudonyme, votre mot de passe ainsi que l'adresse du serveur de chat", "Informations manquantes", JOptionPane.WARNING_MESSAGE); nbr++; } else { try { J = (Contrat) Naming.lookup("rmi://" + jTextField1.getText() + ":1099/JChat"); } catch (RemoteException ex4) { JOptionPane.showMessageDialog( null, "La connexion au serveur a échoué", "Serveur non démarré", JOptionPane.WARNING_MESSAGE); System.out.println(ex4); nbr++; } catch (MalformedURLException ex4) { JOptionPane.showMessageDialog( null, "Connexion 2", "Erreur de connexion", JOptionPane.WARNING_MESSAGE); nbr++; } catch (NotBoundException ex4) { JOptionPane.showMessageDialog( null, "Serveur non joignable", "Erreur de connexion", JOptionPane.WARNING_MESSAGE); System.out.println(ex4); System.exit(0); } if (J != null) { try { // de la méthode connect distante // Récupération de l'adresse de la machine du client try { adr = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex3) { } // Si le nom et le mot de passe fournies par le client sont valides // Envoi du nom et mot de passe pour la vérification de la validité de ce client // ainsi que le num de port // , adresse de la machine du client et nom de l'objet distant du client pour // pouvoir l'invoquer ultérieurementulté num_port = J.get_num_port(); if (J.connect(nom.getText(), new String(pwd.getPassword()), adr, num_port)) { srv_Adr = jTextField1.getText(); srv_state = true; // fermeture de la fenetre de connexion fermer(); try { java.rmi.registry.LocateRegistry.createRegistry(num_port); System.out.println("Ecoute sur le port : " + num_port); // Placement de l'objet distant du client sur sa machine : localhost dans le // registre pour le numéro de port spécifié Naming.rebind("//" + adr + ":" + num_port + "/" + nom.getText(), retourObj()); System.out.println(Naming.list("//" + adr + ":" + num_port)[0]); } catch (MalformedURLException ex2) { System.out.println(ex2); } catch (RemoteException ex1) { System.out.println(ex1); } // Constructeur graphique de la classe Client C = new Client(nom.getText(), new String(pwd.getPassword())); Essai essai = new Essai(); SplashWindowApp splash = new SplashWindowApp(C, 2000, essai); if (J.getnbrcon() >= 2) { System.out.println("Mise à jour de la liste du nouveau connecté"); // Mise à jour de la liste des destinataires du nouveau connecté for (int i = 0; i < J.getnbrcon(); i++) if (J.list_con()[i].compareTo(nom.getText()) != 0) C.ajout(J.list_con()[i]); } } else { JOptionPane.showMessageDialog( null, "Vérifiez votre pseudonyme ou mot de passe"); nbr++; } } catch (RemoteException ex) { System.out.println(ex); } } } if (nbr == 3) { JOptionPane.showMessageDialog(null, "Nombre maximum d'essai est atteint"); System.exit(0); } } } else { if (e.getSource() == Annuler) System.exit(0); } }
public void run() { // ************************************************************************************ String jsonText2 = new String(""); JSONObject obj_out = new JSONObject(); ServerSocket welcomeSocket; while (true) { try { // ********************************************************* welcomeSocket = new ServerSocket(network.api_port, 0, InetAddress.getByName("localhost")); Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); JSONParser parser = new JSONParser(); try { // ********************************************************* statex = "0"; responsex = "e00"; jsonText = ""; if (!clientSentence.contains("")) { throw new EmptyStackException(); } Object obj = parser.parse(clientSentence); jsonObject = (JSONObject) obj; String request = (String) jsonObject.get("request"); String item_id = new String(""); String item_array = new String(""); String old_key = new String(""); String node = new String(""); try { item_id = (String) jsonObject.get("item_id").toString(); } catch (Exception e) { System.out.println("extra info no item_id..."); } try { item_array = (String) jsonObject.get("item_array").toString(); } catch (Exception e) { System.out.println("extra info no item_array..."); } try { old_key = (String) jsonObject.get("key").toString(); } catch (Exception e) { System.out.println("extra info no key..."); } try { node = (String) jsonObject.get("node").toString(); } catch (Exception e) { System.out.println("extra info no node..."); } while (network.database_in_use == 1 && !request.equals("status")) { System.out.println("Database in use..."); try { Thread.sleep(1000); } catch (InterruptedException e) { } } // ************************************************************** if (request.equals("status")) { statex = "1"; responsex = get_status(); } // *************************** else if (request.equals("get_version")) { statex = "1"; responsex = network.versionx; } // else if (request.equals("get_tor_active")) { statex = "1"; responsex = Integer.toString(network.tor_active); } // else if (request.equals("get_last_block")) { statex = "1"; responsex = network.last_block_id; } // else if (request.equals("get_last_block_timestamp")) { statex = "1"; responsex = network.last_block_timestamp; } // else if (request.equals("get_last_block_hash")) { statex = "1"; responsex = network.last_block_idx; } // else if (request.equals("get_difficulty")) { statex = "1"; responsex = Long.toString(network.difficultyx); } // else if (request.equals("get_last_mining_id")) { statex = "1"; responsex = network.last_block_mining_idx; } // else if (request.equals("get_prev_mining_id")) { statex = "1"; responsex = network.prev_block_mining_idx; } // else if (request.equals("get_last_unconfirmed_id")) { statex = "1"; responsex = get_item_ids(); } // else if (request.equals("get_my_token_total")) { statex = "1"; responsex = Integer.toString(network.database_listings_owner); } // else if (request.equals("get_my_id_list")) { statex = "1"; responsex = get_item_ids(); } // else if (request.equals("get_my_ids_limit")) { statex = "1"; responsex = get_item_ids(); } // else if (request.equals("get_token")) { statex = "1"; responsex = get_item_array(item_id); } // else if (request.equals("get_settings")) { statex = "1"; responsex = get_settings_array(); } // else if (request.equals("get_mining_info")) { statex = "1"; responsex = get_item_array(item_id); } // else if (request.equals("get_new_keys")) { statex = "1"; responsex = build_keysx(); } // else if (request.equals("delete_node")) { statex = "1"; responsex = delete_node(node); } // else if (request.equals("delete_all_nodes")) { statex = "1"; responsex = delete_all_nodes(); } // else if (request.equals("set_new_node")) { statex = "1"; responsex = set_new_node(node); } // else if (request.equals("set_old_key")) { statex = "1"; responsex = set_old_key(old_key); } // else if (request.equals("set_new_block")) { statex = "1"; responsex = set_new_block(item_array); } // else if (request.equals("set_edit_block")) { statex = "1"; update_state = "set_edit_block"; responsex = update_token(item_array); } // else if (request.equals("set_transfer_block")) { statex = "1"; update_state = "set_transfer_block"; responsex = update_token(item_array); } // else if (request.equals("system_restart")) { statex = "1"; responsex = "restarting"; toolkit = Toolkit.getDefaultToolkit(); xtimerx = new Timer(); xtimerx.schedule(new RemindTask_restart(), 0); } // else if (request.equals("system_exit")) { statex = "1"; System.exit(0); } // else { statex = "0"; responsex = "e01 UnknownRequestException"; } } // try catch (ParseException e) { e.printStackTrace(); statex = "0"; responsex = "e02 ParseException"; } catch (Exception e) { e.printStackTrace(); statex = "0"; responsex = "e03 Exception"; } JSONObject obj = new JSONObject(); obj.put("response", statex); try { obj.put("message", responsex); } catch (Exception e) { e.printStackTrace(); } StringWriter outs = new StringWriter(); obj.writeJSONString(outs); jsonText = outs.toString(); System.out.println("SEND RESPONSE " + responsex); outToClient.writeBytes(jsonText + '\n'); welcomeSocket.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("Server ERROR x3"); } } // **********while } // runx***************************************************************************************************