running server object method from client-side on the network

hi ,

i have written two little applications one is working on the client-side. the other one is running on the server-side. i have created an interface on both sides with the same name "ServisArayuzu" and these interfaces has one method .

public interface ServisArayuzu { public String getIsim(); } 

both classes on the server and on the client side implements this interface differently.

try { server=new ServerSocket(1500); nextClient=server.accept(); OutputStream os=nextClient.getOutputStream(); ObjectOutputStream oos=new ObjectOutputStream(os); oos.writeObject(new XY("serdar","ilter")); //here XY object is succesfully created oos.flush(); oos.close(); } catch (IOException ioe) { System.err.println ("Error " + ioe); } 


i'am ok establishing the connection with the IP and a port. connection is working.

client-side:
try { client=new Socket("10.10.20.84",1500); ObjectInputStream ois=new ObjectInputStream(client.getInputStream()); ServisArayuzu a= (ServisArayuzu) ois.readObject(); String b=a.getIsim(); txtRemoteX.set_Text(b); client.close(); } catch (IOException ioe) { System.err.println ("Error " + ioe); } catch (ClassNotFoundException cnfe) { System.err.println ("Error " + cnfe); } 


before server-side goes oos.flush() application throws ClassNotFoundException on the client-side. Why how will I run the server-side intance's method getIsim()


Answer this question

running server object method from client-side on the network

  • TheRoon

    Hi,

    Class Metadata means the function signatures, variables names\types.

    Thanks,


  • ronmurp

    is importing package information inclusive to metadata i mean could throwing ClassNotFoundException be the reason of import different package information

  • millerfj

    ok, if we change the state of the object at runtime on the server-side(for example an integer variable is set to 5), when i serialize it, could client see the variable is 5

  • frog37

    Hi,

    You are getting classNotfoundException on client side because we need to refer a class with same metadata on client side as well, otherwise deserialization on client side will fail.

    So you would need to include class XY on client side as well.

    Now if you want to run server-side instance method. Just compile XY on server side into a xy.dll and refer that dll from client side. Then deserialization will be succesful and it would run server side method as well.

    Thanks,

  • CoreyMasson

    could i learn what you do mean by metadata can you give a little example



  • David Zillner

    ok, if we change the state of the object at runtime on the server-side(for example an integer variable is set to 5), when i serialize it, could client see the variable is 5

  • Viper446

    If you don't import right package then your code can't be compiled. It will throw compile time error.
    Package information is also part of metadata. If you are able to complie the code but not able to run becauase of ClassNotFoundException, then you are missing the assembly in which the class is defined. I mean CLR is not able to locate the required assembly.

    If you can post entire exception trace (Stack trace) then we can zero in the issue.

    Thanks.

  • eferreyra

    If you change the state of the variable and you are referencing the same type class(with same metadata) at client side, then it should see the server value.

    Thanks,

  • Srik

    hi ,

    i have written two little applications one is working on the client-side. the other one is running on the server-side. i have created an interface on both sides with the same name "ServisArayuzu" and these interfaces has one method .

    public interface ServisArayuzu{ 
    public String getIsim();
    }


    both classes on the server and on the client side implements this interface differently.

    try
    {
    server=new ServerSocket(1500);
    nextClient=server.accept();
    OutputStream os=nextClient.getOutputStream();
    ObjectOutputStream oos=new ObjectOutputStream(os);
    oos.writeObject(new XY("serdar","ilter"));
    //here XY object is succesfully created
    oos.flush();
    oos.close();
    }
    catch (IOException ioe)
    {
    System.err.println ("Error " + ioe);
    }



    i'am ok establishing the connection with the IP and a port. connection is working.

    client-side:

    try  
    {  
    client=new Socket("10.10.20.84",1500);
    ObjectInputStream ois=new ObjectInputStream(client.getInputStream());    ServisArayuzu a= (ServisArayuzu) ois.readObject();
    String b=a.getIsim();  
    txtRemoteX.set_Text(b);   
    client.close(); 

    catch (IOException ioe)  
    {  
    System.err.println ("Error " + ioe); 
    }  
    catch (ClassNotFoundException cnfe) 
    {   
    System.err.println ("Error " + cnfe); 
    }



    before server-side goes oos.flush() application throws ClassNotFoundException on the client-side. Why how will I run the server-side intance's method getIsim()

  • DIEGOE

    Import information is not part of the class metadata. what we mean by class metadata is the private\protected\public variables, the signature of all functions of the class.



  • running server object method from client-side on the network