you could google jive
that is the forum writen using java

解决方案 »

  1.   

    maybe could help you as sample althought not chatroom
      

  2.   


    // Set up a Server that will receive packets from a
    // client and send packets to a client.// Java core packages
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;// Java extension packages
    import javax.swing.*;public class Server extends JFrame {
       private JTextArea displayArea;
       private DatagramPacket sendPacket, receivePacket;
       private DatagramSocket socket;   // set up GUI and DatagramSocket
       public Server()
       {
          super( "Server" );      displayArea = new JTextArea();
          getContentPane().add( new JScrollPane( displayArea ),
             BorderLayout.CENTER );
          setSize( 400, 300 );
          setVisible( true );      // create DatagramSocket for sending and receiving packets
          try {
             socket = new DatagramSocket( 5000 );
          }      // process problems creating DatagramSocket
          catch( SocketException socketException ) {
             socketException.printStackTrace();
             System.exit( 1 );
          }   }  // end Server constructor   // wait for packets to arrive, then display data and echo
       // packet to client
       public void waitForPackets()
       {
          // loop forever
          while ( true ) {         // receive packet, display contents, echo to client
             try {            // set up packet
                byte data[] = new byte[ 100 ];
                receivePacket =
                   new DatagramPacket( data, data.length );            // wait for packet
                socket.receive( receivePacket );
     
                // process packet
                displayPacket();            // echo information from packet back to client
                sendPacketToClient();
             }         // process problems manipulating packet
             catch( IOException ioException ) {
                displayArea.append( ioException.toString() + "\n" );
                ioException.printStackTrace();
             }      }  // end while   }  // end method waitForPackets   // display packet contents
       private void displayPacket()
       {
          displayArea.append( "\nPacket received:" +
             "\nFrom host: " + receivePacket.getAddress() +
             "\nHost port: " + receivePacket.getPort() +
             "\nLength: " + receivePacket.getLength() +
             "\nContaining:\n\t" +
             new String( receivePacket.getData(), 0,
                receivePacket.getLength() ) );
       }   // echo packet to client
       private void sendPacketToClient() throws IOException
       {
          displayArea.append( "\n\nEcho data to client..." );      // create packet to send
          sendPacket = new DatagramPacket( receivePacket.getData(),
             receivePacket.getLength(), receivePacket.getAddress(),
             receivePacket.getPort() );      // send packet
          socket.send( sendPacket );      displayArea.append( "Packet sent\n" );
          displayArea.setCaretPosition( 
             displayArea.getText().length() );
       }   // execute application
       public static void main( String args[] )
       {
          Server application = new Server();      application.setDefaultCloseOperation(
             JFrame.EXIT_ON_CLOSE );      application.waitForPackets();
       }}  // end class Server
      

  3.   

    // Fig. 17.7: Client.java
    // Set up a Client that will send packets to a
    // server and receive packets from a server.// Java core packages
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;// Java extension packages
    import javax.swing.*;public class Client extends JFrame {
       private JTextField enterField;
       private JTextArea displayArea;
       private DatagramPacket sendPacket, receivePacket;
       private DatagramSocket socket;   // set up GUI and DatagramSocket
       public Client()
       {
          super( "Client" );      Container container = getContentPane();      enterField = new JTextField( "Type message here" );      enterField.addActionListener(         new ActionListener() {            // create and send a packet
                public void actionPerformed( ActionEvent event )
                {
                   // create and send packet
                   try {
                      displayArea.append( 
                         "\nSending packet containing: " +
                         event.getActionCommand() + "\n" );                  // get message from textfield and convert to 
                      // array of bytes
                      String message = event.getActionCommand();
                      byte data[] = message.getBytes();
             
                      // create sendPacket
                      sendPacket = new DatagramPacket( 
                         data, data.length,
                         InetAddress.getLocalHost(), 5000 );                  // send packet
                      socket.send( sendPacket );                  displayArea.append( "Packet sent\n" );
                      displayArea.setCaretPosition(
                         displayArea.getText().length() );
                   }               // process problems creating or sending packet
                   catch ( IOException ioException ) {
                      displayArea.append( 
                         ioException.toString() + "\n" );
                      ioException.printStackTrace();
                   }            }  // end actionPerformed         }  // end anonymous inner class      ); // end call to addActionListener      container.add( enterField, BorderLayout.NORTH );      displayArea = new JTextArea();
          container.add( new JScrollPane( displayArea ),
             BorderLayout.CENTER );      setSize( 400, 300 );
          setVisible( true );      // create DatagramSocket for sending and receiving packets
          try {
             socket = new DatagramSocket();
          }      // catch problems creating DatagramSocket
          catch( SocketException socketException ) {
             socketException.printStackTrace();
             System.exit( 1 );
          }   }  // end Client constructor   // wait for packets to arrive from Server, 
       // then display packet contents
       public void waitForPackets()
       {
          // loop forever
          while ( true ) {         // receive packet and display contents
             try {            // set up packet
                byte data[] = new byte[ 100 ];
                receivePacket = 
                   new DatagramPacket( data, data.length );            // wait for packet
                socket.receive( receivePacket );
     
                // display packet contents
                displayPacket();
             }
     
             // process problems receiving or displaying packet
             catch( IOException exception ) {
                displayArea.append( exception.toString() + "\n" );
                exception.printStackTrace();
             }      }  // end while   }  // end method waitForPackets   // display contents of receivePacket
       private void displayPacket()
       {
          displayArea.append( "\nPacket received:" +
             "\nFrom host: " + receivePacket.getAddress() +
             "\nHost port: " + receivePacket.getPort() +
             "\nLength: " + receivePacket.getLength() +
             "\nContaining:\n\t" +
             new String( receivePacket.getData(), 0,
                receivePacket.getLength() ) );      displayArea.setCaretPosition(
             displayArea.getText().length() );
       }   // execute application
       public static void main( String args[] )
       {
          Client application = new Client();      application.setDefaultCloseOperation( 
             JFrame.EXIT_ON_CLOSE );      application.waitForPackets();
       }}  // end class Client
      

  4.   

    http://www.900-ibm.com上有现成的例子,JAVA版的OICQ
      

  5.   

    大家没明白我的意思哦,实际上就是irc聊天室,客户端只用ie,不下载控件,服务器端一个irc服务器,这个irc服务器有没有java写的呢,有例子么,多谢多谢
      

  6.   

    我写的所谓“推”聊天室依靠的不是服务器端,而是客户端的xmlhttp
      

  7.   

    兄台能把你的xmlhttp的给我看看么:),讲讲原理也行啊
      

  8.   

    xmlhttp依赖于MS的msxml客户端插件,所以通常都只在IE上使用,而且要在5.0以上版本