Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

chat program

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Maged Roshdy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic