aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes chat program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "chat program" Watch "chat program" New topic
Author

chat program

Maged Roshdy
Greenhorn

Joined: Feb 08, 2003
Posts: 24
to develop a chating program (clint/server) how to serve the chating in the server ?
do the server have send a vector that holds all the ip's to every client whenever new client is connected and evrey client have to choose the ip he want to chat with and make new socket to send an outputstream that the other client will recieve in a serversocket.
it means evrey client have to have a
1- socket
2- serversocket
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Maged,
Well, there a lots of ways to implement a client/server application. You could have a server that holds all the addresses of all the registered clients and also provides all the plumbing: connects the chatting clients together. That's fine if you have few clients or a 32 processor server, but soon becomes untenalbe when you have a large number of clients or a slow server. Probably the best architechture would be to have the server just be a dirctory service and as you noted each client could have a Socket and ServerSocket. Or you could use the UDP protocol, DatagramSocket and DatagramPacket, for client to client chatting which would be more efficient but harder to code because UDP does not guarantee either packet order or packet delivery.
Hope this helps,
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Maged Roshdy
Greenhorn

Joined: Feb 08, 2003
Posts: 24
thanks Michael Morris
and sorry for delaying in replay
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 ]
[ February 15, 2003: Message edited by: Maged Roshdy ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: chat program