whiteboard - client server problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: whiteboard - client server problem

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Posts
    20

    whiteboard - client server problem

    I have build a whiteboard application that consist of a client and a server. The client will send the coordinates of what is drawn on a whiteboard to a server. The server is capable of handling multiple clients. The server will receive the coordinates from the clients and broadcast it to all the other clients so that other clients can see what is drawn. The problem I am facing with the code is that my client keeps receiving the same coordinates send to the server and therefore the clients do not get updated. How do I solve the problem?. I attach also the link for the java files:

    http://upload2.net/page/download/43V...board.zip.html

    Your help is kindly appreciated. Also if you require any further information, I would be willing to provide.

    Regards.

    P.S Please take note that this is not a school homework.

  2. #2
    Join Date
    Jul 2005
    Posts
    20
    I enclose herewith the simplified version of the code. The server side is the full code but the client side is a simplified version of code.


    Server Side Code:

    StartServ.java
    --------------------

    import java.net.*;
    import java.io.*;
    import java.util.*;

    public class StartServ
    {
    int portnr = 9000;

    public StartServ()
    {
    try
    {
    ServerSocket serv=new ServerSocket(portnr);
    while(true)
    {
    Socket s=serv.accept();
    System.out.println("Accepted from
    client: "+s.getInetAddress());
    Handler c=new Handler(s);
    c.start();
    }
    }
    catch(IOException e)
    {

    }
    }

    public static void main(String args[])
    {
    new StartServ();
    }
    }


    Handler.java
    ------------------

    import java.net.*;
    import java.io.*;
    import java.util.*;

    class Handler extends Thread
    {
    private Socket socket = null;
    ObjectOutputStream oos1;
    ObjectInputStream oos2;
    Vector ht1;
    protected static Vector list=new Vector();

    public Handler(Socket socket)
    {
    this.socket = socket;

    try
    {
    oos1 = new ObjectOutputStream(socket.getOutputStream());
    oos2 = new ObjectInputStream(socket.getInputStream());
    }
    catch(Exception e)
    {

    }
    }

    public void run()
    {
    try
    {
    list.addElement(this);

    while(true)
    {
    try
    {
    ht1 = (Vector)oos2.readObject();

    System.out.println(ht1.size());
    }
    catch(ClassNotFoundException cnfe)
    {
    System.out.println("class not found!");

    }
    broadcast(ht1);
    }
    }
    catch(IOException e)
    {
    System.out.println("IOException...");
    }
    finally
    {
    list.removeElement(this);

    System.out.println("User exiting...");

    try
    {
    socket.close();

    }
    catch(IOException e)
    {

    }
    }
    }


    protected static void broadcast(Vector ob)
    {
    synchronized(list)
    {
    Enumeration en=list.elements();

    while(en.hasMoreElements())
    {
    Handler eh=(Handler) en.nextElement();
    try
    {
    synchronized(eh.oos1)
    {
    eh.oos1.writeObject(ob);

    System.out.println("Object sent...");
    }
    eh.oos1.flush();

    }
    catch(IOException e)
    {
    eh.stop();
    }
    }
    }
    }
    }


    Client Side:

    WhiteBoard.java
    ------------------------

    public void init()
    {
    ht = new Vector();
    ht2 = new Vector();

    try
    {
    skt = new Socket("localhost", 9000);
    oos = new ObjectOutputStream(skt.getOutputStream());
    ois2 = new ObjectInputStream(skt.getInputStream());
    }
    catch(Exception e)
    {

    }

    new Thread(this).start();
    }

    public void mouseDragged(MouseEvent e)
    {
    drawLines(pre_x + ":" + pre_y + ":" + x + ":" + y);
    }

    public void drawLines(String m)
    {
    ht.add(m);
    }

    public void mouseReleased(MouseEvent e)
    {
    oos.writeObject(ht);
    ht.clear();
    }

Similar Threads

  1. Replies: 1
    Last Post: 10-18-2007, 03:50 PM
  2. Client server Question......Plz help
    By rohan076 in forum Java
    Replies: 1
    Last Post: 03-30-2006, 04:11 AM
  3. Replies: 0
    Last Post: 02-08-2006, 06:55 AM
  4. two server and many client....
    By collinm in forum Java
    Replies: 1
    Last Post: 10-06-2005, 04:35 PM
  5. Replies: 7
    Last Post: 09-15-2000, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center