Hello, if U have that much of patience tell me why sending to Client is not achieved while receiving is possible from client. Ofcoarse that too works only if I commented the sendall class and its thread. The sendall thread broadcasts to everyclients that is being stored in the Vector. Help me if U could!!! plz............ Below is the Server side program: import java.net.*; import java.io.*; import java.util.*; public class Forsc1 { static Vector listof=new Vector(); public static void main(String args[]) { Socket Client; try { ServerSocket ss=new ServerSocket(5555); while(true) { Client=ss.accept(); Receive r=new Receive(Client); System.out.println("connected: "+Client.getInetAddress().getHostName()); r.start(); listof.add(Client); Sendall toall=new Sendall(); toall.start(); } } catch (Exception e) {} } } class Receive extends Thread { Socket client; Vector v=new Vector(); Vector history=new Vector(); ObjectInputStream in; Object o; public Receive(Socket c) { client=c; try { in=new ObjectInputStream(client.getInputStream()); } catch(Exception e) {} } public void run() { int h,q=0; try { synchronized(o) { q++; o=in.readObject(); v=(Vector) o; for(h=0;h<v.size();h++)> { System.out.println("received :"+v.elementAt(h)); } sleep(100); } } catch(Exception e) {} } } class Sendall extends Thread { Vector all; Socket s; Object came; ObjectOutputStream op; Forsc con=new Forsc(); Receive rec; public Sendall() { all=con.listof; came=rec.o; System.out.println("no.of clients ====="+all.size()); } public void run() { for(int k=0;k<all.size();k++)> { try { s=(Socket) all.elementAt(k); op=new ObjectOutputStream(s.getOutputStream()); System.out.println("sending to "+s); op.writeObject(came); } catch(Exception e) {} } } }
I will have a look. For future reference, it helps if you use UBB [code] to preserve the formatting of your listings. Also posting the same question to multiple forums is frowned upon.
Do not post the same message in multiple forums! Post it to the forum that you feel is best for the question. If a moderator feels that it will better be answered in another forum, we will move it there. I'm closing all these except for the one in Sockets forum. Carl Trusiak - Sheriff