2 Attachment(s)
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
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
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:
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
}
}
Re: Problem in passing an object class through socket
Quote:
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.
1 Attachment(s)
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
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.
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.
Re: Problem in passing an object class through socket
Is the program working now?
3 Attachment(s)
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
Re: Problem in passing an object class through socket
Please explain.
What do you do to start execution of the programs?
What do the programs do?
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
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.
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
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.
Quote:
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.
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:(happy):