Java.rmi.connectexception: отказано в соединении с хостом: 127.0.0.1; вложенное исключение:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package myDesign; //import Util.Source; //import com.multicast.MulticastRx; //import com.multicast.MulticastsRx; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.InputStream; import java.io.ObjectInputStream; import java.net.InetAddress; import java.net.MalformedURLException; import java.net.ServerSocket; import java.rmi.Naming; import java.rmi.NotBoundException; import java.rmi.RemoteException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; /** * * @author jp */ public class Router extends javax.swing.JFrame { int v; ServerSocket ss; InputStream is = null; ObjectInputStream ois; InetAddress ip; String getData; String getFName; String getTotalPackets, senderName, receiverIP, sizes, totalPackets; String getdiv; String name, size, packets; // Thread t = new Thread(new Connect()); JScrollPane sp; JTable table; DefaultTableModel model; // Thread t; public Router() { initComponents(); setTitle("Router"); init(); this.getContentPane().setBackground(Color.CYAN); // Thread t = new Thread(new Connect()); // String data[][] = {{"", "", "", "", "", "", "", ""}}; String data[][] = {}; String col[] = { "Q-No", "File", "Sender", "Receiver", "Size", "Total Packets", "Status" }; model = new DefaultTableModel(data, col); table = new JTable(model); // model.insertRow(0, new Object[]{"Ranjan", "50"}); // model.insertRow(3, new Object[]{"Amar", "600"}); // model.insertRow(table.getRowCount(), new Object[]{"", "", "", "", "", // "", "", ""}); table.setBounds(330, 50, 450, 150); sp = new JScrollPane(table); sp.setBounds(330, 50, 650, 190); add(sp); // t.start(); } private void init() { new MulticastRx(this); new MulticastsRx(this); } public class Connect implements Runnable { public void run() { try { String url = "rmi://127.0.0.1/router"; srvint in = (srvint) Naming.lookup(url); System.out.println("Receiving"); ArrayList<String> array = new ArrayList<String>(); array = in.getArray(); getData = array.get(0); getFName = array.get(1).trim(); senderName = array.get(2).trim(); receiverIP = array.get(3).trim(); sizes = array.get(4).trim(); totalPackets = array.get(5).trim(); int uu = Integer.parseInt(totalPackets); for (int k = 1; k <= uu; k++) { Thread.sleep(300); model.insertRow(table.getRowCount(), new Object[] { table.getRowCount(), getFName, senderName, receiverIP, sizes, totalPackets, "packet " + k }); jTextArea3.append("Packet " + k + " Received"+"\n"); } Thread.sleep(300); model.insertRow(table.getRowCount(), new Object[] { table.getRowCount(), getFName, senderName, receiverIP, sizes, totalPackets, "Completed" }); // while (table.getRowCount() > 0) { // model.removeRow(0); // } JOptionPane .showMessageDialog(null, "File receive Completed..!"); } // GEN-LAST:event_jButton1ActionPerformed catch (InterruptedException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); }catch (NotBoundException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoteException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } } } @SuppressWarnings("unchecked") private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); jTextArea3 = new javax.swing.JTextArea(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); jButton5 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMinimumSize(new java.awt.Dimension(1000, 650)); getContentPane().setLayout(null); jLabel1.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jLabel1.setText("Receive Nodes"); getContentPane().add(jLabel1); jLabel1.setBounds(20, 244, 140, 20); jLabel2.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jLabel2.setText("Packets In Queue"); getContentPane().add(jLabel2); jLabel2.setBounds(300, 254, 160, 20); jTextArea1.setColumns(20); jTextArea1.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); getContentPane().add(jScrollPane1); jScrollPane1.setBounds(10, 80, 160, 150); jTextArea2.setColumns(20); jTextArea2.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jTextArea2.setRows(5); jScrollPane2.setViewportView(jTextArea2); getContentPane().add(jScrollPane2); jScrollPane2.setBounds(10, 270, 160, 150); jButton1.setText("Receive"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton1.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N //jButton1.setText("BottleNeck Queue"); getContentPane().add(jButton1); jButton1.setBounds(60, 440, 110, 30); jLabel3.setFont(new java.awt.Font("Algerian", 0, 24)); // NOI18N jLabel3.setText("Using Fuzzy Logic Control To Provide Intelligent Traffic Management Service"); getContentPane().add(jLabel3); jLabel3.setBounds(10, 10, 990, 30); jTextArea3.setColumns(20); jTextArea3.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jTextArea3.setRows(5); jScrollPane3.setViewportView(jTextArea3); getContentPane().add(jScrollPane3); jScrollPane3.setBounds(210, 290, 530, 240); jButton2.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jButton2.setText("Memory Used"); getContentPane().add(jButton2); jButton2.setBounds(760, 430, 190, 30); jButton2.addActionListener(new Actions()); jButton3.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jButton3.setText("Router Traffic"); getContentPane().add(jButton3); jButton3.setBounds(760, 310, 190, 30); jButton3.addActionListener(new Actions()); jButton4.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jButton4.setText("BottleNeck Queue"); getContentPane().add(jButton4); jButton4.setBounds(760, 370, 190, 30); jButton4.addActionListener(new Actions()); jLabel4.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N jLabel4.setText("Source Nodes"); getContentPane().add(jLabel4); jLabel4.setBounds(20, 54, 120, 20); jButton5.setText("Transfer"); jButton5.setFont(new java.awt.Font("Agency FB", 0, 24)); // NOI18N getContentPane().add(jButton5); jButton5.setBounds(60, 490, 113, 30); jButton5.addActionListener(new Actions()); pack(); }// </editor-fold>//GEN-END:initComponents public class Actions implements ActionListener { public void actionPerformed(ActionEvent e) { if(e.getSource()==jButton2){ new MemoryUsed().setVisible(true); } if(e.getSource()==jButton3){ new RouterTraffic().setVisible(true); } if(e.getSource()==jButton4){ new BottleNeck().setVisible(true); } if (e.getSource() == jButton5) { try { ArrayList<String> array1 = new ArrayList<String>(); array1.add(0, getData); array1.add(1, getFName); array1.add(2, senderName); array1.add(3, receiverIP); array1.add(4, sizes); array1.add(5, totalPackets); System.out.println(getData); System.out.println(getFName); System.out.println(senderName); System.out.println(receiverIP); System.out.println(sizes); System.out.println(totalPackets); JOptionPane.showMessageDialog(null, "Transfering"); String url1 = "rmi://127.0.0.1/" + receiverIP; srvint in1 = (srvint) Naming.lookup(url1); System.out.println("hello ok"); // System.out.println(in1.getArray()); in1.setArray1(array1); JOptionPane .showMessageDialog(null, "Transfering completed"); } catch (NotBoundException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } catch (RemoteException ex) { Logger.getLogger(Router.class.getName()).log(Level.SEVERE, null, ex); } } } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Thread t = new Thread(new Connect()); t.start(); }// GEN-LAST:event_jButton1ActionPerformed /** * @param args * the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // <editor-fold defaultstate="collapsed" // desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase * /tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager .getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Router.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Router.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Router.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Router.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } // </editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Router().setVisible(true); try { srvimp rob = new srvimp(); Naming.rebind("router", rob); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; public javax.swing.JTextArea jTextArea1; public javax.swing.JTextArea jTextArea2; public javax.swing.JTextArea jTextArea3; // End of variables declaration//GEN-END:variables }
Что я уже пробовал:
Пишу код IP адреса роутера есть
String url = "rmi://127.0.0.1/router";
Но что показывает ошибка это
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect