em muốn chạy chương trình Client - Server (Internet)

nmt129700

New Member
25/4/21
2
0
1
đại học dân quốc
- em hok biết còn thiếu lỗi ở đâu sau không chạy đc Client - Server (Internet)

- chạy trên mạng LAN ok. trả kế quả, nhưng không chạy được trên INTERNET

p/s: em có một máy cài làm máy chủ sử dụng ddns.
em với một mạng khác (ở ngoài thì chương trình không chạy được)

XIN ANH/CHI/EM giúp đỡ

--------------------------------------------------------
Java:
package rmicalserver;

import java.rmi.Remote;
import java.rmi.RemoteException;

/**
*
* @author
*/
public interface IMath extends Remote {
       public int add(int a, int b) throws RemoteException;
       public int sub(int a, int b) throws RemoteException;
       public int mul(int a, int b) throws RemoteException;
       public int div(int a, int b) throws RemoteException;

}
--------------------------------------------------------------
Java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package rmicalserver;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
*
* @author
*/
public class MathObject extends UnicastRemoteObject implements IMath{

    public MathObject() throws RemoteException{
        super();
}
    @Override
    public int add(int a, int b) throws RemoteException {
     
        return a+b; //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int sub(int a, int b) throws RemoteException {
        return a-b; //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int mul(int a, int b) throws RemoteException {
        return a*b; //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int div(int a, int b) throws RemoteException {
        return a/b; //To change body of generated methods, choose Tools | Templates.
    }
 
}
-------------------------------------------------------------------------
Java:
package rmicalserver;

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;

/**
*
* @author
*/
public class RMIServer {
 
    public static void main(String[] args) {
        try {
            LocateRegistry.createRegistry(9989);
            Naming.rebind("rmi://localhost:9989/MyServices", new MathObject());
            System.out.println("Server started.....");
        } catch (Exception e) {
        }
    }
}
--------------------------------------------------------
Java:
package rmiclient;

import java.rmi.Naming;
import rmicalserver.IMath;

/**
*
* @author
*/
public class RMIClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            IMath imath = (IMath) Naming.lookup("rmi://daicattuong.ddns.net:9989/MyServices");
            int rs = imath.add(2, 4);
            System.out.println("return = "+rs);
        } catch (Exception e) {
        }
    }
 
}
-------------------------------------------------------
 
Last edited by a moderator:

Joe

Thành viên VIP
21/1/13
2,927
1,314
113
daicattuong.ddns.net
Is this name the name of your localhost? If YES then the next question: is daicattuong.ddns.net registered as a domain? If YES. Next question again: is the port 9989 FORWARDED by your MODEM (or Router)? If YES: Then it must work.
BUT: if the last question is a NO then you have to do the forwarding on your MODEM.
HOW? It depends on the type of your MODEM you use to go to the WEB. Read the manual and look for the FORWARDING chapter.