• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in chatting program  RSS feed

 
Maged Roshdy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the server
-------------
when i send a vector ( which carries all the IP's of connected clients ) to every client by useing a single thread to every client
class WriteToClient extends Thread
{
public void run()
{
try
{
for(int i=0 ; i<vec2.size() ; i++)
{
Socket s=(Socket)vec2.get(i);
oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(vec);
}
}catch(Exception e){e.printStackTrace();}
}
}

// where vec2 is a vector that holds all sockets
// where vec is a vector that holds all IP's
in the client i receive
-----------------------
java.io.StreamCorruptedException: InputStream does not contain a serialized object
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:849
)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:168)
at ChatClient$NewClientConnect.run(ChatClient.java:133)

while the Vector class implements Serializable interface
and the code fragment in the client is:
class NewClientConnected extends Thread
{
public void run()
{
try
{
while(true)
{
oos=new ObjectInputStream(s.getInputStream());
Vector vec=(Vector)oos.readObject();
}
}catch(Exception e)
{e.printStackTrace();}
}
}

and i don't know what's wrong ?

please help
Thanks in advance
--------------------
[ February 15, 2003: Message edited by: Maged Roshdy ]
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maged,
Without seeing all of your code, it's hard to say what the problem is. Just a suggestion, but it seems to me that there are a couple of better designs for getting the list of logged clients to all the other clients. Datagrams would probably be a better way. You could have a dedicated thread on the server that went thru the list of registered clients every minute or so and send a datagram with a delimited list of clients to everyone. Another way would be to have the clients connect to the server every minute or so to get the current list. Or maybe even better, combine the two, whenever a new client logs on or one logs out, have the server send a datagram to all client indicating a change in the list. Then the clients could connect to get the updated list.
Hope this helps,
Michael Morris
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!