how to create a chat page for logged in users. please tell.

Recommended Answers

All 6 Replies

I do not think will be that easy to type the whole the codes here for you. But if you explain better I can send you some scripts.

Shaswat, create a chat page. Use Java. Create applet for use client. Use for server java socketServer. Multi thread. Write more descriptive threads please.

can u guide me step by step

Guiding you step by step on your project is not the function of DaniWeb. However here is a very broad step by step process that you can use for any project:

  1. Decide what it is that you are doing. (chat page for logged in users)
  2. Refine your decision into a broad design (what parts are needed)
  3. Design each part (how will the data flow, what are the various screens, how are they related to each other, how will data be stored, etc)
  4. Write some tests for the infrastructure (framework) part of your code. They will all fail, but must compile, so write stubs for each of the infrastructure components.
  5. Now, one failure at a time, replace stub code with real code until you have no more test failures (keep adding tests as you see places that need to be improved or extended) When all the tests pass, your framework is ready to be used.
  6. Write some tests for the 'user' part of your project. All the tests will fail, but they must compile. Keep adding stub code until they do compile. Write more tests as you discover problem areas. These "user' stubs are also the units that will need to have documents, so as you write the tests, write the docs too (in fact, you may want to do it in the other order)
  7. One test failure at a time, add code to make the 'user' tests succeed. Always run all your tests after every step to be sure your new code has not broken something that you already did.
  8. When all the tests pass and your documentation is clean, your project is done (don't we all wish it were that easy)

When you have designed the framework (as griswolf has outlined) around your requirements and written some classes you should post back the code that yields errors and we can help you with that. We can also help you think about your problems as they may arise. We do NOT write software to your requirements and then guide you to the same conclusions.

To help you get started, you should start gathering requirements from your clients. Think about designing a use case for the business logic of your software. Organize the actors of your use case into UMLs entities to design the classes of your software. Write the frame work, test the software.

In this thread, please make the code you post relevant to either SQL or databases, any other questions that do not meet that criteria should be posted to the subject matter appropriate forum categories (Java, PHP, ASP, javascript, etc).

ok, let me help.. here's al little code on chat agent.

here's is the first part for the server ..

//Server Application
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*; 
public class ServerApp extends Frame implements ActionListener,Runnable 
{
    ServerSocket s;
    Socket s1;
    BufferedReader br;
    BufferedWriter bw;
    TextField text;
    Button button1,button2;
    List list;
    public void run()
    {
        try{s1.setSoTimeout(1);}catch(Exception e){}
        while (true)
        {
            try{
            list.addItem(br.readLine());
            }catch (Exception h){}
        }
    }
    public static void main(String[] args)
    {
        new ServerApp("Server Applicaton:");

    }

    public ServerApp(String m)
    {
        super(m);
        setSize(200,300);
        setLocation(0,0);
        this.setLayout(new BorderLayout());
        button1 = new Button("Send");
        button2 = new Button("Exit");
        button1.addActionListener(this);
        button2.addActionListener(this);
        list = new List();
        text = new TextField();
        add(list,"Center");
        add(button1,"West");
        add(button2,"East");        
        add(text,"South");
        setVisible(true);
        try{
            s = new ServerSocket(100);

            s1=s.accept();
            br = new BufferedReader(new InputStreamReader(
                    s1.getInputStream()));
            bw = new BufferedWriter(new OutputStreamWriter(
                    s1.getOutputStream()));
            bw.write("Hello");bw.newLine();bw.flush();
             Thread th;
             th = new Thread(this);
             th.start();


        }catch(Exception e){}
    }
    public void actionPerformed ( ActionEvent e)
    {
         if (e.getSource().equals(button2))
             System.exit(0);
         else{try{
             bw.write(text.getText());
             bw.newLine();bw.flush();
             text.setText("");
             }catch(Exception m){}
         }

    }

}

here is the second part for the client

//Client Application
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class Client extends Frame implements ActionListener,Runnable 
{
    Socket s;
    BufferedReader br;
    BufferedWriter bw;
    TextField text;
    Button button1,button2;
    List list;
    public static void main(String arg[])
    {
        new Client("Client Applicaton:");

    }
    public void run()
    {
        try{s.setSoTimeout(1);}catch(Exception e){}
        while (true)
        {
            try{list.addItem(br.readLine());
            }catch (Exception h){}
        }
    }

    public Client(String m)
    {
        super(m);
        setSize(200,300);
        setLocation(300,0);

        this.setLayout(new BorderLayout());
        button1 = new Button("Send");
        button2 = new Button("Exit");
        button1.addActionListener(this);
        button2.addActionListener(this);
        list = new List();
        text = new TextField();
        add(list,"Center");
        add(button1,"West");
        add(button2,"East");        
        add(text,"South");
        setVisible(true);
        try{
            /*Put the current IP address for current machine  
            if you didn't have an actual server and clients
            if you have an actual server and clients put the client IP address*/
            s = new Socket("127.0.0.1",100);
            br = new BufferedReader(new InputStreamReader(
                    s.getInputStream()));
            bw = new BufferedWriter(new OutputStreamWriter(
                    s.getOutputStream()));
            Thread th;
            th = new Thread(this);
            th.start();

        }catch(Exception e){}

    }
    public void actionPerformed ( ActionEvent e)
    {
         if (e.getSource().equals(button2))
             System.exit(0);
         else{try{
             bw.write(text.getText());
             bw.newLine();bw.flush();

              }catch(Exception m){}
         }

    }

}

hope the code helped.. just notify me ok,? my mail is justice_gift@yahoo.com or code_lin@yahoo.com thanks thats all i have for now

commented: Posting entire Java codes does not help the OP nor does it foster an expectation conducive to OPs coming up with their own solution through honest independent work. Java related posts should be posted to the java forum. See the DW rules +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.