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;
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;
JScrollPane sp;
JTable table;
DefaultTableModel model;
public Router() {
initComponents();
setTitle("Router");
init();
this.getContentPane().setBackground(Color.CYAN);
String data[][] = {};
String col[] = { "Q-No", "File", "Sender", "Receiver", "Size",
"Total Packets", "Status" };
model = new DefaultTableModel(data, col);
table = new JTable(model);
table.setBounds(330, 50, 450, 150);
sp = new JScrollPane(table);
sp.setBounds(330, 50, 650, 190);
add(sp);
}
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" });
JOptionPane
.showMessageDialog(null, "File receive Completed..!");
}
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));
jLabel1.setText("Receive Nodes");
getContentPane().add(jLabel1);
jLabel1.setBounds(20, 244, 140, 20);
jLabel2.setFont(new java.awt.Font("Agency FB", 0, 24));
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));
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));
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));
getContentPane().add(jButton1);
jButton1.setBounds(60, 440, 110, 30);
jLabel3.setFont(new java.awt.Font("Algerian", 0, 24));
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));
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));
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));
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));
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));
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));
getContentPane().add(jButton5);
jButton5.setBounds(60, 490, 113, 30);
jButton5.addActionListener(new Actions());
pack();
}
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");
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();
}
public static void main(String args[]) {
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);
}
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) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
});
}
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;
}
What I have tried:
I write the code of IP address of router is
String url = "rmi://127.0.0.1/router";
But which shows error is
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect