الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ConnectionException in RMI

بدأه Game111 في 18 مايو 2011 · 5 رد · 445 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام علكيم

انا كتبت RMI سيرفر و كلينت علما انهم في جهازين مختلفين و لكن يحدث خطأ في الاتصال , لا اعلم ما السبب ConnectionException (timeout

سيرفر

 import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author NEW
 */
 interface ServerInterface extends Remote
  {
  public String Display()
  throws RemoteException;
}
public class Server extends UnicastRemoteObject implements ServerInterface{
    private static String Message="Welcome to our server";

    public Server() throws RemoteException {
        super();
    }

    public  String Display() throws RemoteException {
        return Message;
    }
    public static void main(String[]args) throws RemoteException
    {

       try
       {
           Server obj=new Server();
           Naming.bind("service", obj);

       }
       catch (RemoteException e)
  {
          System.out.println(""+e.getMessage());
       }
        catch (AlreadyBoundException e)
       {
           System.out.println(""+e.getMessage());
       }
       catch (MalformedURLException e)
       {
           System.out.println(""+e.getMessage());
    }



}
}

كلينت

 import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
interface ServerInterface extends Remote
  {
  public String Display()
  throws RemoteException;
}
/**
 *
 * @author NEW
 */

public class Client  {
public static void main (String args[])

{

    try
    {
        ServerInterface handle=(ServerInterface)Naming.lookup("rmi://newtech-pc/service");
        System.out.println(handle.Display());
    }
    catch (Exception e)
    {
        System.out.println(""+e.getMessage());
    }


}
}

و هل يمكنني تشغيل واجهة في حهاز الكلينت و هي مكتوبة في السيرفر عن طريق RMI ؟؟؟؟

تم تعديل هذه المشاركة بواسطة Game111 في 18 مايو 2011 في 13:54

#2

لست خبيرا في الجافا ار ام اي ، ولكن برايي ان المشكله من اعدادات الشبكه ، لان الاتصال يقوم بtimeout اي ان الاتصال فشل

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#3

هل يعملان جيدا على نفس الجهاز؟

#4
mental-driller كتب:

لست خبيرا في الجافا ار ام اي ، ولكن برايي ان المشكله من اعدادات الشبكه ، لان الاتصال يقوم بtimeout اي ان الاتصال فشل

شكرا

هويدي كتب:

هل يعملان جيدا على نفس الجهاز؟

لم اجرب و لكني سأجرب و اعطيكم النتيجة

#5

نعم انهم يعملان على نفس الجهاز و لكنهم لا يعملان على جهازين مختلفين و السبب عدم قدر الكلينت على الاتصال بالسيرفر timeout ConnectionException و السبب لا اعلم

ارجو المساعدة و هذا الكود

سيرفر

  public class Server extends UnicastRemoteObject implements ServerInterface{
    private static String Message="Welcome to our server";

    public Server() throws RemoteException {
        super();
    }

    public  String Display() throws RemoteException {
        return Message;
    }

}

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

/**
 *
 * @author NEW
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws MalformedURLException {
          try
       {
           Server obj=new Server();
        Naming.bind("rmi://newtech-pc/service", obj);
Registry registry=LocateRegistry.getRegistry();

System.out.println("server is ready");

       }
       catch (RemoteException e)
  {
          System.err.println(""+e.getMessage());
       }
        catch (AlreadyBoundException e)
       {
           System.err.println(""+e.getMessage());
       }



        // TODO code application logic here
    }

}

الانترفيس للسيرفر في ملف منفصل

import java.rmi.RemoteException;

/**
 *
 * @author NEW
 */
public interface ServerInterface extends java.rmi.Remote {
public String Display() throws RemoteException;
}

الكلينت

 import java.rmi.RemoteException;

/**
 *
 * @author NEW
 */
public interface ServerInterface extends java.rmi.Remote {
public String Display() throws RemoteException;
}

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 *
 * @author NEW
 */
public class C {
public static void main (String[]args) throws NotBoundException, MalformedURLException
    {
    try
    {
        ServerInterface handle=(ServerInterface)Naming.lookup("rmi://newtech-pc/service");
        System.out.println(handle.Display());
    }
    catch(RemoteException e)
    {
        System.out.println(e.getMessage());
    }
    }
}

تم تعديل هذه المشاركة بواسطة Game111 في 21 مايو 2011 في 22:56

#6

تأكد من عدم وجود برنامج جدار ناري يوقف الاتصال سواءاً على المرسل أو على المستقبل

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

مواضيع مشابهة