Results 1 to 16 of 16
  1. #1
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Problem in passing an object class through socket

    I have a client server programm where each client can send a message to the others the problem in passing an object class through socket ,it goes well with the theory but when the server recieves the message there is an exception:

    line 186:
    [B]server: Data received in unknown format[/B ]

    catch(ClassNotFoundException classnot)
    {
    System.err.println("server: Data received in unknown format");
    }

    to run the program first you have to run the MultiChatServerObj with no pramaters and the the MultiChatObj at the following way:
    MultiChatObj name localhost
    like MultiChatObj james localhost

    I will be most thankfull if you find the error ,reading material on the subject doesn't help tried to put the class in a Vector and transmitt the Vevtor instead but it didn't help

    bye
    Attached Files Attached Files
    Last edited by alladin; 02-04-2012 at 12:29 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    For testing: Create a new class with a main method that calls the other two classes in the correct order with the correct arguments to make it very simple for anyone to test the code.
    Something like:
    Server.main(new String[] {"name", "localhost"}); // call main method and pass the correct args

  3. #3
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    i can't succeed i wrote a program but it does'nt work
    it is very simple to run both programs as i explained at the original post

    here is the program that doesn't work:
    Java Code:
    package UNIVERSITY.Java.MultiChatObj;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ClientServer {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            //Server.main(new String[] {"name", "localhost"}); 
          String  MultiChatObjparam1 []={"james","local host"};
          String  MultiChatObjparam2 []={"billy","local host"};
          //MultiChatObj a = new MultiChatObj();
          //MultiChatObj b = new MultiChatObj();
         // MultiChatServerObj c=new MultiChatServerObj();
          MultiChatServerObj.main("");
          MultiChatObj.main(MultiChatObjparam1);
          MultiChatObj.main(MultiChatObjparam2);
                  // TODO code application logic here
        }
    }
    Last edited by Norm; 02-04-2012 at 05:22 PM. Reason: added code tags

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    program that doesn't work:
    Please explain.
    Post the full text of the error messages.

    My IDE doesn't easily allow me to start more than one program at a time. If the programs are configured so there is only one program to start the testing will be easier. I prefer to have the easiest testing possible.
    Last edited by Norm; 02-04-2012 at 05:25 PM.

  5. #5
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    the program:

    package UNIVERSITY.Java.MultiChatObj;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ClientServer {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    //Server.main(new String[] {"name", "localhost"});
    String MultiChatObjparam1 []={"james","localhost"};
    //String MultiChatObjparam2 []={"billy","localhost"};

    new MultiChatServerObj.main();
    new MultiChatObj.main(MultiChatObjparam1);
    // new MultiChatObj.main(MultiChatObjparam2);

    // TODO code application logic here
    }
    }

    the error messages are in the attachment
    Attached Files Attached Files

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    Please post everything on the forum. Make it easier for those that want to see the problem and help by having it ALL here.

    Several things wrong with your call of the main() method.
    main() is static you do NOT need the new
    main() takes a String array as an argument.

    See the sample I posted.
    Last edited by Norm; 02-04-2012 at 06:16 PM.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    One problem I see is there are two different Person classes in the different packages.

    Make one version of the class that is used by all.

  8. #8
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default It works!

    now it works previously i ran the program with the windows xp cmd
    may be the firewall blocked something

    i correted the main ,getting out one declaration of person class from MultiCharObj

    package UNIVERSITY.Java.MultiChatObj;
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    public class ClientServer {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {

    String MultiChatObjparam1 []={"james","localhost"};
    String MultiChatObjparam2 []={"billy","localhost"};
    MultiChatServerObj.main(new String[] {""});
    MultiChatObj.main(MultiChatObjparam1);
    MultiChatObj.main(MultiChatObjparam2);

    // TODO code application logic here
    }
    }
    Attached Files Attached Files

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    Is the program working now?

  10. #10
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    This is a client server program in which the clients has 2
    parameters name and localhost to run on local machine
    any client who writse a message send it to the server that broadcasts it to all the clients which recieve the message in their text area

    It was working for a while and then it stopped
    ,the problem is
    that the server that is been launched first has a while loop waiting for the clients ,so the computer can't track the clients that being launched after him and the server can't do the accept for this clients

    here are the programs the main is ClientServer, the client is MultiChatObj and the server is MultiChatServerObj

    that is the only problem as i said before the program worked properly for a while

    i tried to run it form the cmd , to launch the server and run the clients form the java beans but it doesn't work

    thanks for your help
    Attached Files Attached Files
    Last edited by alladin; 02-13-2012 at 12:18 PM.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    it doesn't work
    Please explain.
    What do you do to start execution of the programs?
    What do the programs do?

  12. #12
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    These are the lines to to start execution of the programs at ClientServer program:

    String MultiChatObjparam1 []={"james","localhost"};
    String MultiChatObjparam2 []={"billy","localhost"};
    MultiChatServerObj.main(new String[] {""});
    MultiChatObj.main(MultiChatObjparam1);
    MultiChatObj.main(MultiChatObjparam2);

    This is a client server program in which the clients has 2
    parameters name and localhost to run on local machine
    any client who writse a message send it to the server that broadcasts it to all the clients which recieve the message in their text area

    the main is ClientServer, the client is MultiChatObj and the server is MultiChatServerObj
    Last edited by alladin; 02-13-2012 at 01:48 PM.

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    Can you explain what does not work?

    Does the call to:
    MultiChatServerObj.main(new String[] {""});
    return so that the next statement is executed?

    Add a println after it to verify.

  14. #14
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    next statemnt (the client is not execeuted) it worked previously i dont know how and then i saw how the server broadcasts the message to all the clients

    the desired working method is to run the serer and then launch the client via the cmd
    java -jar "path" name localhost but when i write such a thing i see a text screen flash for a second but it doesn;t remain stable
    Last edited by alladin; 02-13-2012 at 02:22 PM.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default Re: Problem in passing an object class through socket

    If the MultiChatServerObj.main(new String[] {""});
    statement does not return, then the client code that follows it will not be executed.
    Put the call to MultiChatServerObj.main(new String[] {""}); in a Thread and start the thread.
    That will allow the following client code to be executed.

    launch the client via the cmd
    java -jar "path" name localhost
    but when i write such a thing i see a text screen flash for a second but it doesn;t remain stable
    Copy all of the command prompt console and post it here.
    On MS Windows:
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  16. #16
    alladin is offline Member
    Join Date
    Jan 2012
    Posts
    11
    Rep Power
    0

    Default Re: Problem in passing an object class through socket

    it works!!!
    Thank you very much a message now can be send from the text area to each of the clients

Similar Threads

  1. Replies: 3
    Last Post: 05-02-2011, 04:37 AM
  2. Replies: 9
    Last Post: 12-15-2010, 02:38 AM
  3. Replies: 2
    Last Post: 10-28-2010, 02:33 PM
  4. Problem with class Object
    By marak in forum New To Java
    Replies: 9
    Last Post: 07-24-2010, 03:40 PM
  5. Passing SWT object to another class
    By Vinaya Lal Shrestha in forum SWT / JFace
    Replies: 0
    Last Post: 04-03-2009, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •