Java Chat (Server, Client Socket Connection)

Assignment:
The assignment is to deliver two source codes that can run a Server (1) and Clients (2) in order to create a simpel chat program. The server has to wait and check an IP (localhost) + Port, and the client has to connect to that port and create a socket connection. The only thing that should be done is create a new socket connection for each client... and when a client sends a message, the message should be delivered to all clients connected to the server.
Problem...
However I can read an edit Java, it's difficult for me to write it. I allready found many turturials about socket connections on the internet, and tried to edit those, but they don't really do what I want unless I really write new shit. Is there a way you guys can help me with this, or that you find a really good website that fits my question?

According to me ,
take string variable 'str'
Take some class ,I think u already taken.....
Scoket scoket = new Socket(IP,port);
OutputStream out;
IInputStream in;
in = socket.getInputStream();
out = socket.getOutputStream();
If sends the msg then use
out.writeObject(str);
This line sends data to the other user
msg resivce from client then use
str = in.readInput();
& this str set to the any objects out put .
Such as TextField.setText(str);
//Server.class
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Server extends JFrame
          private JTextField enterdField;
          private JTextArea displayArea;
          private ObjectOutputStream output;
          private ObjectInputStream input;
          private ServerSocket server;
          private Socket connection;
          private int counter=1;
          public Server()
                    super("Server");
                    enterdField = new JTextField();
                    enterdField.setEditable(false);
                    enterdField.addActionListener(
                         new ActionListener()
                                   public void actionPerformed(ActionEvent event)
                                             sendData(event.getActionCommand());
                                             //System.out.println(event.getActionCommand());
                                             enterdField.setText("");
               add(enterdField,BorderLayout.NORTH);
               displayArea = new JTextArea();
               add(new JScrollPane(displayArea),BorderLayout.CENTER);
               setSize(300,150);
               setVisible(true);
          public void runServer()
                    try
                              server = new ServerSocket(12345,100);
                              while(true)
                                        try
                                                  waitForConnection();
                                                  getStreams();
                                                  processConnection();
                                        catch(EOFException eofexception)
                                                  displayMessage("\nServer terminated connection");
                                        finally
                                                  closeConnection();
                                                  counter++;
                    catch(IOException ioException)
                              ioException.printStackTrace();
          private void waitForConnection() throws IOException
                    displayMessage("Waiting for connection");
                    connection = server.accept();
                    //System.out.println(server.accept());
                    System.out.println(connection.getInetAddress());//Server Address and Hostname.
                    displayMessage("Connection"+counter +"received from :"+connection.getInetAddress().getHostName());
          private void getStreams() throws IOException
                    System.out.println("Start getStream");
                    output = new ObjectOutputStream(connection.getOutputStream());
                    output.flush();
                    input = new ObjectInputStream(connection.getInputStream());
                    displayMessage("\nGot I/O stream\n");
          private void processConnection() throws IOException //Read data from Client for Server.
                    String message="Connection sucessful To Client";
                    sendData(message);
                    int i=0;
                    setTextFieldEditable(true);
                    do
                              try
                                        message =(String) input.readObject();//For Client
                                        System.out.println("Input from :"+message);//From Client
                                        displayMessage("\n" + message);
                                        System.out.println("\n" + i++);
                              catch(ClassNotFoundException classnotfoundexception)
                                        displayMessage("\nUnknown object type recived");
                    while(!message.equals("CLIENT>>>TERMINATE"));
          private void closeConnection()
                    displayMessage("\nTeminating connection");
                    setTextFieldEditable(false);
                    try
                              output.close();
                              input.close();
                              connection.close();
                    catch(IOException ioException)
                              ioException.printStackTrace();
          private void sendData(String message)//Write data to the Client from the Server.
                    try
                              output.writeObject("SERVER>>>"+message);//For Client side.
                              System.out.println(message);
                              output.flush();
                              displayMessage("\nSERVER>>>"+message);//On server side.
                    catch(IOException ioException)
                              displayMessage("\nError writing object");
          private void displayMessage(final String messageToDisplay)
                    SwingUtilities.invokeLater(
                         new Runnable()
                              public void run()
                                        displayArea.append(messageToDisplay);
          private void setTextFieldEditable(final boolean editable)
                    SwingUtilities.invokeLater(
                         new Runnable()
                              public void run()
                                        enterdField.setEditable(editable);
          public static void main(String q[])
                    Server app = new Server();
                    app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    app.runServer();
//Client.class
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Client extends JFrame
     private JTextField enterField;
     private JTextArea displayArea;
     private ObjectOutputStream output;
     private ObjectInputStream input;
     private String message="";
     private String chatServer;
     private Socket client;
     public Client (String host)
               super("Client");
               chatServer=host;
               enterField = new JTextField();
               enterField.setEditable(false);
               enterField.addActionListener(
                    new ActionListener()
                              public void actionPerformed(ActionEvent event)
                                        sendData(event.getActionCommand());
                                        enterField.setText("");
                    add(enterField,BorderLayout.NORTH);
                    displayArea = new JTextArea();
                    add(new JScrollPane(displayArea),BorderLayout.CENTER);
                    setSize(300,150);
                    setVisible(true);
     public void runclient()
               try
                         connectToServer();
                         getStreams();
                         processConnection();
               catch(EOFException eofException)
                         displayMessage("\nClient treminated connection");
               catch(IOException ioException)
                         ioException.printStackTrace();
               finally
                         closeConnection();
     private void connectToServer() throws IOException
               displayMessage("Attempting connection\n");
               client = new Socket(InetAddress.getByName(chatServer),12345);
               displayMessage("Connect to:"+client.getInetAddress().getHostName());
     private void getStreams() throws IOException
               output = new ObjectOutputStream(client.getOutputStream());
               output.flush();
               input = new ObjectInputStream(client.getInputStream());
               //Thread t = new Thread(this,"Thread");
               //t.start();
               displayMessage("\nGot I/O stream\n");
     private void processConnection( ) throws IOException
               setTextFieldEditable(true);
               do
                         try
                                   message=(String)input.readObject();
                                   displayMessage("\n"+message);
                         catch(ClassNotFoundException classnotfoundexception)
                                   displayMessage("\nUnknown object type received");
               while(!message.equals("SERVER>>>TERMINATE"));
     private void closeConnection()
               displayMessage("\n Closing connection");
               setTextFieldEditable(false);
               try
                         output.close();
                         input.close();
                         client.close();
               catch(IOException ioException)
                         ioException.printStackTrace();
     private void sendData(String message)
               try
                         output.writeObject("CLIENT>>>"+message);
                         //System.out.println(message);
                         output.flush();
                         displayMessage("\nCLIENT>>>"+message);
               catch(IOException ioException)
                         displayArea.append("\n Error writing object");
     private void displayMessage(final String MessageToDisplay)
               SwingUtilities.invokeLater(
                    new Runnable()
                              public void run()
                                        displayArea.append(MessageToDisplay);
     private void setTextFieldEditable(final boolean editable)
               SwingUtilities.invokeLater(
                    new Runnable()
                              public void run()
                                        enterField.setEditable(editable);
     public static void main(String q[])
               Client app;
               if(q.length==0)
                         app = new Client("127.0.0.1");
               else
                         app = new Client(q[0]);
               app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               app.runclient();
Use this example .....
Give me reply.My method is correct or not
All the best

Similar Messages

  • Server/Client Socket Connection

    Hi, I am trying to program a simple server/client socket connection program, the main function is to send and receive objects between them. I somehow went wrong and the connection between them keeps terminating right after establishing connection. Is there anything I can do to resolve this?
    This is gonnna be kinda long post.. sorry. These are the code that starts and ends the socket connection. I'm kinda desperate for this to work.. so thanks in advance.
    appinterface.java:
    //Set up server to receive communications; process connections. 1x.
         public void runServer () {
              try {
                   //Create a ServerSocket
                   server = new ServerSocket(12345, 100);
                   try {
                             waitForSockConnection();     //Wait for a connection.
                             getSockStreams();               //Get input & output streams.
                             establishDbConnection();     //Open up connection to DB.
                   finally {
                             closeSockConnection(); //Close connection.
              //Process problems with I/O
              catch(IOException ioException) {
                   displayMessage("I/O Error: " + ioException);
                   runServer();
         //Wait for connection to arrive, then display connection info
         private void waitForSockConnection() throws IOException {
              displayMessage("Waiting for connection");
              connection = server.accept(); //Allow server to accept connection.
              displayMessage("Connection received from: " + connection.getInetAddress().getHostName());
         //Get streams to send and receive data.
         private void getSockStreams() throws IOException {
              //Set up output streams for objects
              ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
              output.flush(); //Flush output buffer to send header information.
              //Set up input stream for objects.
              ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
              try {
              classHolderServer holderObj = new classHolderServer();
              holderObj = (classHolderServer)input.readObject();
              processSockConnection(holderObj);
              displayMessage("Got I/O Streams");
              //Catch problems reading from client
              catch (ClassNotFoundException classNotFoundException) {
                             displayMessage("Unknown object type received");
         //Process connection with client.
         private void processSockConnection(classHolderServer holderObj) throws IOException {
              //sendMessage("Connection Successful");
                        //True is query, and false is auth.
                        if(holderObj.type1==true)
                             processDbStatement(holderObj.type2, holderObj.sqlquery);
                        else {
                             authCheck(holderObj.userName, holderObj.passWord);
                             if(!authCheck)
                             closeDbConnection();
         //Send messages to client.
         private void sendMessage(String message) {
              // Send message to client
              try {
                   ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
                   output.flush();
                   output.writeObject(message);
                   output.flush();
                   displayMessage("Message Sent:" + message);
              catch (IOException ioException) {
                   displayMessage("\nError Sending Message: " + message);
         //Send object to client
         private void sendObject(Object holderObj) {
                   // Send object to client
                   try {
                        ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
                        output.writeObject(holderObj);
                        output.flush();
                        displayMessage("\nObject sent");
                   //Process problems sending object
                   catch (IOException ioException) {
                        displayMessage("\nError writing object");
         //Close streams and socket.
         private void closeSockConnection() {
                   displayMessage("Terminating connection");
                   try {
                        //output.close();
                        //input.close();
                        connection.close();
                        closeDbConnection();
                        this.userName = null;
                        this.passWord = null;
                        this.receiverId = 0;
                        this.authCheck = false;
                   catch (IOException ioException) {
                        displayMessage("I/O Error: " + ioException);
              }Client:
    private void runClient() {
              //Connect to sever and process messages from server.
              try{
                   connectToServer();
                   getStreams();
                   processConnection();
              //Server closed connection.
              catch(EOFException eofException) {
                   //displayMessage"Client Terminated Connection");
              //Process problems communicating with server.
              catch (IOException ioException) {
                   //displayMessage"Communication Problem");
              finally {
                   closeConnection();
         //Connect to server
         private void connectToServer() throws IOException {
              //displayMessage("Attempting connection\n");
              //Create Socket to make connection to sever.
              client = new Socket(InetAddress.getByName(chatServer), 12345);
              //Display connection information
              //displayMessage("Connected to: " + client.getInetAddress().getHostName());
         //Get streams to send and receive data.
         private void getStreams() throws IOException {
              //Set up output stream for objects.
              ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
              output.flush(); //Flush outout buffer to send header information.
              //Set up input stream for objects.
              ObjectInputStream input = new ObjectInputStream(client.getInputStream());
              //displayMessage("\nGot I/O streams\n");
         //Close socket connection.
         private void closeConnection() {
              //displayMessage("\nClosing connection");
              try {
                   ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                   output.close();
                   ObjectInputStream input = new ObjectInputStream(client.getInputStream());
                   input.close();
                   client.close();
                   authCheck=false;
              catch(IOException ioException) {
                   ioException.printStackTrace();
         //Send data to server.
         private void sendObject(classHolderClient queryObj) {
              try {
                   output.writeObject(queryObj);
                   output.flush();
                   //displayMessage("Please wait..");
              //Process problems sending object.
              catch (IOException ioException) {
                   //displayMessage("\nError writing object");
         //Process connection with server.
         private void processConnection() throws IOException {
              try{
                   classHolderClient holderObj = new classHolderClient();
                   holderObj = (classHolderClient)input.readObject();
                   if(holderObj.type2==2) {
                             this.authCheck=holderObj.authCheck;
                             this.userName=holderObj.userName;
                             this.passWord=holderObj.passWord;
              catch(ClassNotFoundException classNotFoundException) {
                   //displayMessage(classNotFoundException);
              }

    private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());Like this? But this will cause an error asking me to catch an exception:
    C:\Documents and Settings\Moon\My Documents\Navi Projects\School\OOPJ Project\Prototype\GPS-Lite v2 Alpha Debugger\client.java:41: unreported exception java.io.IOException; must be caught or declared to be thrown
            private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                                                                                             ^
    C:\Documents and Settings\Moon\My Documents\Navi Projects\School\OOPJ Project\Prototype\GPS-Lite v2 Alpha Debugger\client.java:41: unreported exception java.io.IOException; must be caught or declared to be thrown
            private ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
                                                ^
    2 errors

  • Java Chat, server/client*x

    Hey,
    I'm trying to make a chat and I've made the server and client, and the server can accept several clients. Only; they communicate client-server, and not client-server-client (if you get what I mean) like I want them to, pretty obviously, since its a chat. I'm still very new to this, heres my code anyhow:
    Server
    import java.net.*;
    import java.io.*;
    public class OJChatServer{
         public static void main(String[] args) throws IOException{
              int port=2556;
              boolean listening = true;
              ServerSocket cServerSocket = null;
              try{
                   cServerSocket = new ServerSocket(port);
                   System.out.println("Server started; Waiting for client(s) to connect.");
              } catch(IOException e){
                   System.err.println("Could not listen on port: "+port);
                   System.exit(1);
              while(listening){
                   try{
                        new handleClient(cServerSocket.accept()).start();
                   } catch(IOException e){
                        System.err.println("Accept has failed");
                        System.exit(1);
              cServerSocket.close();
         static class handleClient extends Thread{
              private Socket clientSocket = null;
              private PrintWriter send;
              private BufferedReader recieve;
              private String inputString, outputString;
              private String clientName = "";
              public handleClient(Socket acceptedSocket){
                   //super("handleClient");
                   this.clientSocket = acceptedSocket;
              public void run(){
                   try{
                        recieve = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                        send = new PrintWriter(clientSocket.getOutputStream(), true);
                        inputString = recieve.readLine();
                        clientName = inputString;
                        System.out.println("Client \""+clientName+"\" has connected. ("+clientSocket+")");
                        while(inputString != null){
                             outputString = processInput(inputString);
                        //     outputString = send.readLine();
                             send.println(outputString);
                             if(inputString.equalsIgnoreCase("Quit")||inputString.equalsIgnoreCase("/Quit")) break;
                             inputString = recieve.readLine();
                        System.out.println("Client \""+clientName+"\" has disconnected. ("+clientSocket+")");
                   send.close();
                   recieve.close();
                   clientSocket.close();
                   } catch(IOException e){
                        //e.printStackTrace();
                        System.out.println("Client \""+clientName+"\" has disconnected. ("+clientSocket+")");
              }//run()
              static String processInput(String theInput){
                   String theOutput = "From server. Test";
                   return theOutput;
         }//handleClient
    }//OJChatServer---------------------------------------------------------------------------------------------
    Client
    import java.net.*;
    import java.io.*;
    public class OJChatClient{
         public static void main(String[] args) throws IOException{
              String nickname = "Guest";
              String host = "localhost";
              int port = 2556;
              Socket cClientSocket = null;
              PrintWriter send = null;
              BufferedReader recieve = null;
              BufferedReader stdIn = null;
              String fromServer, fromUser;
              System.out.println("Welcome to Ove's Java Chat!\nFor help and commands type: /help");
              nickname = KeyboardReader.readString("Enter nickname: ");
              System.out.println("Connecting to host...");
              try{
                   cClientSocket = new Socket(host, port);
                   send = new PrintWriter(cClientSocket.getOutputStream(), true);
                   System.out.println("Connection established.");
              } catch(UnknownHostException e){
                   System.err.println("Unknown host: "+host);
                   System.exit(1);
              } catch(IOException e){
                   System.err.println("Couldn't get I/O for connection: "+host+"\nRequested host may not exist or server is not started");
                   System.exit(1);
              send.println(nickname);
              stdIn = new BufferedReader(new InputStreamReader(System.in));
              recieve = new BufferedReader(new InputStreamReader(cClientSocket.getInputStream()));
              while((fromServer = recieve.readLine())!=null){
                   System.out.println("Server: "+fromServer);
                   fromUser = stdIn.readLine();
                   if(fromUser!=null){
                        //System.out.println(nickname+": "+fromUser);
                        send.println(fromUser);
                   if(fromUser.equalsIgnoreCase("Quit")||fromUser.equalsIgnoreCase("/Quit")) break;
              System.out.println("Closing connection...");
              send.close();
              recieve.close();
              stdIn.close();
              cClientSocket.close();
              System.out.println("Connection terminated.");
              System.out.println("Goodbye and happy christmas!");
    }I want to make it graphical too, but I want to make it work like it should, before i tackle trying Swing out. This code isn't completely complete yet, as you can see. It doesn't handle the clients messages correctly yet.
    What I want to know is how i should send a message from a client to all the other Sockets on the server.

    It compiles, but it gives an error when the client connects.
    import java.net.*;
    import java.io.*;
    public class OJChatServer4{
         static Socket[] clientSockets = new Socket[100];
         static int socketCounter = 0;
         public static void main(String[] args) throws IOException{
              int port=2556;
              boolean listening = true;
              ServerSocket cServerSocket = null;
              try{
                   cServerSocket = new ServerSocket(port);
                   System.out.println("Server started; Waiting for client(s) to connect.");
              } catch(IOException e){
                   System.err.println("Could not listen on port: "+port);
                   System.exit(1);
              while(listening){
                   try{
                        clientSockets[socketCounter] = cServerSocket.accept();
                        new handleClient(clientSockets[socketCounter]).start();
                        socketCounter++;
                   } catch(IOException e){
                        System.err.println("Accept has failed");
                        System.exit(1);
              cServerSocket.close();
         static class handleClient extends Thread{
              private Socket clientSocket = null;
              public static PrintWriter send;
              private BufferedReader recieve;
              private String inputString, outputString;
              private String clientName = "";
              public handleClient(Socket acceptedSocket){
                   //super("handleClient");
                   this.clientSocket = acceptedSocket;
              public void run(){
                   try{
                        recieve = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                        send = new PrintWriter(clientSocket.getOutputStream(), true);
                        inputString = recieve.readLine();
                        clientName = inputString;
                        System.out.println("Client \""+clientName+"\" has connected. ("+clientSocket+")");
                        while(inputString != null){
                             //outputString =
                             processInput(inputString);
                        //     outputString = send.readLine();
                             send.println(outputString);
                             if(inputString.equalsIgnoreCase("Quit")||inputString.equalsIgnoreCase("/Quit")) break;
                             inputString = recieve.readLine();
                        System.out.println("Client \""+clientName+"\" has disconnected. ("+clientSocket+")");
                   send.close();
                   recieve.close();
                   clientSocket.close();
                   } catch(IOException e){
                        //e.printStackTrace();
                        System.out.println("Client \""+clientName+"\" has disconnected. ("+clientSocket+")");
              }//run()
              static void processInput(String theInput) throws IOException{
                   //String theOutput = "Test From server.";
                   PrintWriter sendToAll;
                   sendToAll = new PrintWriter(clientSockets[socketCounter].getOutputStream(), true);
                   for(int i=0;i<socketCounter;i++){
                        sendToAll.println(theInput);
                   //return theOutput;
         }//handleClient
    }//OJChatServer

  • Can Java make server side socket connections?

    I plan on placing a java file (application or applet I don't know) on a website and have my application connect to the java file and tell it to connect to another host (outside of the website's domain) and send and receive data. Is this possible? If not why? If so, then should it be an applet or an application? Would I need to have it listen on a specific port or what?
    I read this (http://java.sun.com/sfaq/):
    "How can an applet open a network connection to a computer on the internet?
    Applets are not allowed to open network connections to any computer, except for the host that provided the .class files. This is either the host where the html page came from, or the host specified in the codebase parameter in the applet tag, with codebase taking precendence.
    For example, if you try to do this from an applet that did not originate from the machine foo.com, it will fail with a security exception:
    Socket s = new Socket("foo.com", 80, true);"
    - sun
    And it through me for a loop.

    Think about this:
    Any webpage may contain an applet.
    Imagine the security implications if an applet could do whatever the developer wanted (erase your hard-drive, read your data, run your programs) without your permission.
    Network connections are another example of the same thing.
    Imagine you visit a webpage and an applet pops up that uses your computer to make a connection to government websites in an attempt to hack them.
    Yikes.
    So basically what happens (by default) is an applet starts of with a reduced set of permissions to protect the end user.
    An application (by default) starts with more permissions you'd expect an application to have.
    This is all configurable by the person who will be running the Applet or application. If someone trusts you, they can set up their runtime to give your applet all permissions, or give it a particular set of permissions. Or you can sign the applet with a digital signature, and if the end user trusts the certificate, and trusts you they can give your applet permissions that way.
    Java Security, however, is not something that can be covered in one post on the forums.
    You should probably look for some online tutorials/documentation or get a good book.

  • Trying to produce a java chat server

    Would like produce a working client/server chat system, as basic as possible but able to listen and talk to each other. Any chat servers how-to examples I've come across never seem to work.
    Would like to understand why applets don't work when I open the web page but do work when I view using the appletviewer. I use Internet Explorer 4 i think, java version 1.3.0_02
    would you understand at least part of this error which appears when I run a chat server
    exception:com.ms.security.SecurityExceptionEx[Client.<int>]:cannot access "194.81.104.26":5660
    (the error is all one line no spaces)
    the following code is one of the programs I've been working on and I receive the above error, appletviewer doesn't work so i think that means something is wrong with the code, client side as the server side works well, it listens etc
    // Client side
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class Client extends Panel implements Runnable
    // Components for the visual display of the chat windows
    private TextField tf = new TextField();
    private TextArea ta = new TextArea();
    // The socket connecting us to the server
    private Socket socket;
    // The streams we communicate to the server; these come
    // from the socket
    private DataOutputStream dout;
    private DataInputStream din;
    // Constructor
    public Client( String host,int port ) {
    // Set up the screen
    setLayout( new BorderLayout() );
    add( "North", tf );
    add( "Center", ta );
    // Receive messages when someone types a line
    // and hits return, using an anonymous class as
    // a callback
    tf.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    processMessage( e.getActionCommand() );
    // Connect to the server
    try {
    // Initiate the connection
    socket = new Socket( host, port );
    // Recieved a connection
    System.out.println( "connected to "+socket );
    // Create DataInput/Output streams
    din = new DataInputStream( socket.getInputStream() );
    dout = new DataOutputStream( socket.getOutputStream() );
    // Start a background thread for receiving messages
    new Thread( this ).start();
    } catch( IOException ie ) { System.out.println( ie ); }
    // Called when the user types something
    private void processMessage( String message ) {
    try {
    // Send it to the server
    dout.writeUTF( message );
    // Clear out text input field
    tf.setText( "" );
    } catch( IOException ie ) { System.out.println( ie ); }
    // Background thread runs this: show messages from other window
    public void run() {
    try {
    // Receive messages one-by-one, forever
    while (true) {
    // Get the next message
    String message = din.readUTF();
    // Print it to our text window
    ta.append( message+"\n" );
    } catch( IOException ie ) { System.out.println( ie ); }
    // ClientApplet
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    public class ClientApplet extends Applet
    public void init() {
    //String host = getParameter( "host" );
         String host="194.81.104.26";
         //int port = Integer.parseInt( getParameter( "port" ) );
         int port =5660;
    setLayout( new BorderLayout() );
    add( "Center", new Client( host, port ) );
    // server
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Server
    // The ServerSocket is used for accepting new connections
    private ServerSocket ss;
    // A mapping from sockets to DataOutputStreams. This will
    // help us avoid having to create a DataOutputStream each time
    // we want to write to a stream.
    private Hashtable outputStreams = new Hashtable();
    // Constructor and while-accept loop all in one.
    public Server( int port ) throws IOException {
    // listening
    listen( port );
    private void listen( int port ) throws IOException {
    // Create the ServerSocket
    ss = new ServerSocket( port);
    // ServerSocket is listening
    System.out.println( "Listening on "+ss );
    // Keep accepting connections forever
    while (true) {
    // The next incoming connection
    Socket s = ss.accept();
    // Connection
    System.out.println( "Connection from "+s );
    // Create a DataOutputStream for writing data to the
    // other side
    DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
    // Save this stream so we don't need to make it again
    outputStreams.put( s, dout );
    // Create a new thread for this connection, and then forget
    // about it
    new ServerThread( this, s );
    // Get an enumeration of all the OutputStreams, one for each client
    // connected to us
    Enumeration getOutputStreams() {
    return outputStreams.elements();
    // Send a message to all clients (utility routine)
    void sendToAll( String message ) {
    // We synchronise on this because another thread might be
    // calling removeConnection()
    synchronized( outputStreams ) {
    // For each client ...
    for (Enumeration e = getOutputStreams(); e.hasMoreElements(); ) {
    // ... get the output stream ...
    DataOutputStream dout = (DataOutputStream)e.nextElement();
    // ... and send the message
    try {
    dout.writeUTF( message );
    } catch( IOException ie ) { System.out.println( ie ); }
    // Remove a socket, and it's corresponding output stream, from our
    // list. This is usually called by a connection thread that has
    // discovered that the connectin to the client is dead.
    void removeConnection( Socket s ) {
    // Synchronise so sendToAll() is okay while it walks
    // down the list of all output streams
    synchronized( outputStreams ) {
    // Removing connection
    System.out.println( "Removing connection to "+s );
    // Remove it from our hashtable/list
    outputStreams.remove( s );
    // Make sure it's closed
    try {
    s.close();
    } catch( IOException ie ) {
    System.out.println( "Error closing "+s );
    ie.printStackTrace();
    // Main routine
    // Usage: java Server <port>
    static public void main( String args[] ) throws Exception {
    // Get the port # from the command line
    int port = Integer.parseInt( args[0] );
         //int port = 5000;
    // Create a Server object, which will automatically begin
    // accepting connections.
    new Server( port);
    // ServerThread
    import java.io.*;
    import java.net.*;
    public class ServerThread extends Thread
    // The Server that spawned
    private Server server;
    // The Socket connected to our client
    private Socket socket;
    // Constructor.
    public ServerThread( Server server, Socket socket ) {
    // Save the parameters
    this.server = server;
    this.socket = socket;
    // Start up the thread
    start();
    // This runs in a separate thread when start() is called in the
    // constructor.
    public void run() {
    try {
    // Create a DataInputStream for communication; the client
    // is using a DataOutputStream to write to us
    DataInputStream din = new DataInputStream( socket.getInputStream() );
    // Over and over, forever ...
    while (true) {
    // ... read the next message ...
    String message = din.readUTF();
    // ... sending printed to screen ...
    System.out.println( "Sending "+message );
    // ... and have the server send it to all clients
    server.sendToAll( message );
    } catch( EOFException ie ) {
    // This doesn't need an error message
    } catch( IOException ie ) {
    // This needs an error message
    ie.printStackTrace();
    } finally {
    // The connection is closed for one reason or another,
    // so have the server dealing with it
    server.removeConnection( socket );
    <body bgcolor="#FFFFFF">
    <applet code="ClientApplet" width=600 height=400>
    <param name=host value="127.0.0.1">
    <param name=port value="5660">
    [Chat applet]
    </applet>
    </body>

    Hi!
    Go to
    http://www.freecode.com/projects/jchat-java2clientserverchatmodule/
    probably u will het the answer..
    Jove

  • SocketPermissions for Chat Server/Client Applet

    Hi,
    I've coded a chat server/client applet and found that I need to set socketpermissions when using over the net.
    I put the following line in my java.policy file under my jdk
    permission java.net.SocketPermission ":6288", "connect,accept, listen";
    but it still tells me:
    java.security.AccessControlException: access denied(java.net.SocketPermission 217.0.0.1:6288 connect, resolve)
    any ideas? or am I doing something wrong?
    Also I havent set anything for my applet, and wouldnt know how to? if you do have to set permissions for that, do you put the permissions in with the code or something?
    Thanks in advance.
    Matt.

    ah, dont worry, I've got it fixed.
    that 217.0.0.1 address is because I typed the error by the way, usually it would have my IP.
    problem was I had forgot to recompile with my new assigned IP, d'oh!

  • Need some help on JAVA CHAT SERVER

    i need some info about java chat server. Please any one who have developed give me the details about the logic and process flow.

    Have you read any of these?
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22chat+server%22&col=javaforums

  • Java Application Server 9 - TCP connections

    I have installed Sun Java Application Server 9 and I see that the java process that is started has a lot (more than 30) of TCP connections with a local and a remote address that are both the hostname of the machine that run JAS.
    Can someone tell me what are these connections and if there is a way to decrease the amount of these connections?
    Thank you

    I have installed Sun Java Application Server 9 and I see that the java process that is started has a lot (more than 30) of TCP connections with a local and a remote address that are both the hostname of the machine that run JAS.
    Can someone tell me what are these connections and if there is a way to decrease the amount of these connections?
    Thank you

  • Java chat server . . . help!

    i do macromedia flash and well i downloaded this chat flash java chat. now i know nothing about java, and i do have the sdk and java runtimes. as well as the program bluej. now the guy eho made this chat talks about putting up a server and modifing ports and the like. heres a link of what it says:
    http://guardians_of_vox.tripod.com/readme.txt
    now can anyone tell me what to do or what to get, cause i am a total n00b at this.

    Do you have any specific problems? What have you done? What is not working?

  • Simple server/client socket in applets code.

    Can anyone please help me with Java sockets ? I want to create an applet that simply checks if it's still online. This means that i'll be using this applet thru modem(that is, dial-up connection). All i want the applet to do is send a signal to the server and the server answer back that it is still online. The server should be able to handle multiple sends and receives. I need just a simple code for me to work on (both server and client). The client doesn't have to send any special message to the server and vice versa.
    Thanks.

    Below is the code for both Applet and Servlet .I think this will solve your problem.
    Applet:
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    public class OnlineApplet extends Applet implements Runnable
         private static Thread thread;
         private static HttpURLConnection URLConn;
         public void init()
              try
                   //Connect to the URL where servlet is running.
                   URL url = new URL("http://localhost/servlet/OnlineServlet");
                   URLConn = (HttpURLConnection)url.openConnection();
                   URLConn.setDoInput(false);
                   URLConn.setDoOutput(true);
              catch (Exception ex)
              thread = new Thread(this);
         public void start()
              thread.start();
         public void paint(Graphics g) {}
         public void stop() { }
         public void destroy() { }
         public void run()
              while(true)
                   try
                        thread.sleep(1000 * 60);
                        sendConfirmation();
                   catch (Exception ex)
         private void sendConfirmation() throws Exception
              DataOutputStream dos = new DataOutputStream(URLConn.getOutputStream());
              dos.writeChars("Fine");
              dos.flush();
              dos.close();
    Servlet:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class OnlineServlet extends HttpServlet implements Runnable
         public static Hashtable hsh;
         private static Thread thread;
         public void init(ServletConfig scon) throws ServletException
              hsh = new Hashtable();
              thread = new Thread(this);
         public void service(HttpServletRequest req, HttpServletResponse res)
              String strHostName = req.getRemoteHost();
              if(hsh.containsKey(strHostName))
                   updateHash(strHostName);
              else
                   hsh.put(strHostName, System.currentTimeMillis() + "");
         private void updateHash(String strHostName)
              hsh.remove(strHostName);
              hsh.put(strHostName, System.currentTimeMillis() + "");
         public void run()
              while(true)
                   try
                        thread.sleep(1000 * 120);
                   catch (Exception ex)
                   validateUsers(System.currentTimeMillis());
         private void validateUsers(long msec)
              Enumeration keys = hsh.keys();
              int size = hsh.size();
              while(keys.hasMoreElements())
                   String strKey = keys.nextElement().toString();
                   String strLong = hsh.get(strKey).toString();
                   long lg1 = Long.parseLong(strLong);
                   if((lg1 - msec) > 100000)
                        // This means there is no response from user . That means he is not online. So you can remove from hashtable.
                        hsh.remove(strKey);

  • Yes, its another chat server/client program

    Im busy writing a chat program and am having a problem figuring out how to show the users that are online. The ChatServer class contains methods for recieving messages, broadcasting messages, accepting new connections etc.
    Im using non-blocking mode and I register all the connections with a Selector. When a new user connects to the server, I add the SocketChannel to a LinkedList which contains all the users that are online.
    My problem is that my ChatServer class runs completly seperatly from any other classes (I presume thats normal?). In other words, I run the ChatServer and once that is running I run the StartGUI class which creates the swing gui and all of that. I then type in the host name etc and connect to the server. So how would I show the users that are online? Even if I can somehow get all the ip addresses then ill figure out how to give 'nicks' and all that from there.
    As I said, I have a line (LinkedList.add(newChannel) which adds the clients to that list which I simply did so that i can display the number of users online. Is there a way I could now manipulate that LinkedList to get all the users and then display them (since it contains a list of all the SocketChannels)? Or would that not be possible?
    If it is possible to get the users from the LinkedList, then the other problem is the fact that the list is created as part of the ChatServer so I cant get to it?
    Another way that I thaught might be possible, is that since I register all the keys with a Selector when a new user is added (this happens in the ChatClient clas), then I might be able to get the users from that but im not sure if thats possible?
          readSelector = Selector.open();
          InetAddress addr = InetAddress.getByName(hostname);
          channel = SocketChannel.open(new InetSocketAddress(addr, PORT));
          channel.configureBlocking(false);
          channel.register(readSelector, SelectionKey.OP_READ, new StringBuffer());Ill add to my explanation if need be, since im very new to this sort of programming. Ill post some more code if need be.
    thanks, R

    Through some more playing around this afternoon ive figured out how im going to solve my problem. It may not be the best way to do it but I think that at least it is going to work.
    Im going to convert the LinkedList to a String and then change that into a ByteBuffer, and use channel.write(ByteBuffer) as if it was any other normal message.
    My logic will be as follows:
    Client: click 'get user list' button --> send String 'get users' to the server using channel.write("get users")
    Server: read the String like any other normal String 'channel.read(ByteBuffer) --> decode the ByteBuffer back into a String --> if the String sais "get users" --> put the LinkedList into a String and then into a ByteBuffer --> send the buffer using channel.write(buffer)
    Client: check the incoming buffer for some or other string (maybe an ip address) that will let it know that it is the list of users and not a normal string. Then use a bit of String manipulation to extract the IP addresses from the String.
    Is this a reasonable way of doing it? Any other ideas?
    Also,...Is it alright to add the linked list to a String and then into a ByteBuffer to send? Since if there are for example 100 users online then it will be quite a big string and therefore there will be a lot going into the buffer and being sent by the server. Are there any potential problems I could run into here with lots of users?
    (lol, its been great talking to myself here ;) , hopefully some of you will have some comments or ideas after the weekend.)
    R

  • I chat server not accepting connections

    Over the weekend I had to restart my OS X 10.6 server and now its refusing connections.
    IN the log I am getting this:
    Mar 5 13:25:19 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=40142] connect
    Mar 5 13:25:19 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:25:19 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=40142] disconnect jid=unbound, packets: 0
    Mar 5 13:25:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47985] connect
    Mar 5 13:25:22 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:25:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47985] disconnect jid=unbound, packets: 0
    Mar 5 13:25:27 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44158] connect
    Mar 5 13:25:27 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:25:27 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44158] disconnect jid=unbound, packets: 0
    Mar 5 13:25:34 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46537] connect
    Mar 5 13:25:34 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:25:34 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46537] disconnect jid=unbound, packets: 0
    Mar 5 13:27:10 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=48266] connect
    Mar 5 13:27:10 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:27:10 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=48266] disconnect jid=unbound, packets: 0
    Mar 5 13:27:16 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47383] connect
    Mar 5 13:27:16 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:27:16 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47383] disconnect jid=unbound, packets: 0
    Mar 5 13:27:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39618] connect
    Mar 5 13:27:22 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:27:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39618] disconnect jid=unbound, packets: 0
    Mar 5 13:27:25 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47220] connect
    Mar 5 13:27:25 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:27:25 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=47220] disconnect jid=unbound, packets: 0
    Mar 5 13:29:17 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=49131] connect
    Mar 5 13:29:17 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:29:17 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=49131] disconnect jid=unbound, packets: 0
    Mar 5 13:29:37 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=33481] connect
    Mar 5 13:29:37 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:29:37 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=33481] disconnect jid=unbound, packets: 0
    Mar 5 13:30:35 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=48416] connect
    Mar 5 13:30:35 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:30:35 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=48416] disconnect jid=unbound, packets: 0
    Mar 5 13:30:38 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=34258] connect
    Mar 5 13:30:38 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:30:38 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=34258] disconnect jid=unbound, packets: 0
    Mar 5 13:30:45 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44397] connect
    Mar 5 13:30:45 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:30:45 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44397] disconnect jid=unbound, packets: 0
    Mar 5 13:32:45 ichat Apple80211 framework[993]: ACInterfaceGetPower called with NULL interface
    Mar 5 13:33:27 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=45934] connect
    Mar 5 13:33:27 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:33:27 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=45934] disconnect jid=unbound, packets: 0
    Mar 5 13:34:04 ichat /System/Library/CoreServices/CCacheServer.app/Contents/MacOS/CCacheServer[209]: No valid tickets, timing out
    Any ideas? Need any more info?
    John Gibson

    I found this thread here:
    http://discussions.apple.com/thread.jspa?messageID=12723285&#12723285
    I was wondering if this might be my problem.
    I went into my server admin, clicked on Network
    Computer Name is: ichat
    Local host name is ichat
    Network interfaces DNS name is set to ichat.maddockdouglas.com
    Under the Ichat services general tab the host domain is : ichat.local
    also thought I would post the full ichat log... since I didn't do this earlier.
    So here it is:
    r 5 13:54:24 ichat jabberd/s2s[145]: [8] [74.125.155.125, port=5269] sending dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 13:54:24 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.80, port=60310] checking dialback verification from gmail.com: sending valid
    Mar 5 13:54:24 ichat jabberd/s2s[145]: [8] [74.125.155.125, port=5269] outgoing route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 13:54:24 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.80, port=60310] incoming route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 13:55:01 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=43727] connect
    Mar 5 13:55:01 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:55:01 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=43727] disconnect jid=unbound, packets: 0
    Mar 5 13:55:07 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44335] connect
    Mar 5 13:55:07 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 13:55:07 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=44335] disconnect jid=unbound, packets: 0
    Mar 5 14:24:40 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.80, port=60310] disconnect, packets: 3
    Mar 5 14:24:46 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46178] connect
    Mar 5 14:24:46 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:24:46 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46178] disconnect jid=unbound, packets: 0
    Mar 5 14:47:22 ichat jabberd/c2s[143]: [7] [::ffff:68.20.0.127, port=55348] connect
    Mar 5 14:47:22 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:47:22 ichat jabberd/c2s[143]: [7] [::ffff:68.20.0.127, port=55348] disconnect jid=unbound, packets: 0
    Mar 5 14:47:34 ichat jabberd/c2s[143]: [7] [::ffff:68.20.0.127, port=55357] connect
    Mar 5 14:47:34 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:47:34 ichat jabberd/c2s[143]: [7] [::ffff:68.20.0.127, port=55357] disconnect jid=unbound, packets: 0
    Mar 5 14:48:05 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] incoming connection
    Mar 5 14:48:05 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] incoming stream online (id krmsc593fy88nmejx9uhx956wk1oqli1q3m0ey3z)
    Mar 5 14:48:05 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] received dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 14:48:05 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 209.85.225.125:5269 (300 seconds to live)
    Mar 5 14:48:05 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.155.125:5269 (1800 seconds to live)
    Mar 5 14:48:05 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.47.125:5269 (1800 seconds to live)
    Mar 5 14:48:05 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.45.125:5269 (1800 seconds to live)
    Mar 5 14:48:05: --- last message repeated 1 time ---
    Mar 5 14:48:05 ichat jabberd/s2s[145]: [9] [74.125.45.125, port=5269] outgoing connection
    Mar 5 14:48:05 ichat jabberd/s2s[145]: [9] [74.125.45.125, port=5269] sending dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 14:48:06 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] checking dialback verification from gmail.com: sending valid
    Mar 5 14:48:06 ichat jabberd/s2s[145]: [9] [74.125.45.125, port=5269] outgoing route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 14:48:06 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] incoming route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 14:49:55 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=41533] connect
    Mar 5 14:49:55 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:49:55 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=41533] disconnect jid=unbound, packets: 0
    Mar 5 14:53:36 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39330] connect
    Mar 5 14:53:36 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:53:36 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39330] disconnect jid=unbound, packets: 0
    Mar 5 14:53:42 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=34482] connect
    Mar 5 14:53:42 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:53:42 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=34482] disconnect jid=unbound, packets: 0
    Mar 5 14:53:52 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46140] connect
    Mar 5 14:53:52 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:53:52 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=46140] disconnect jid=unbound, packets: 0
    Mar 5 14:54:17 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=38203] connect
    Mar 5 14:54:17 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:54:17 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=38203] disconnect jid=unbound, packets: 0
    Mar 5 14:54:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=40829] connect
    Mar 5 14:54:22 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:54:22 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=40829] disconnect jid=unbound, packets: 0
    Mar 5 14:54:32 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=37880] connect
    Mar 5 14:54:32 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:54:32 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=37880] disconnect jid=unbound, packets: 0
    Mar 5 14:54:49 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39674] connect
    Mar 5 14:54:49 ichat jabberd/c2s[143]: SASL callback for non-existing host: ichat.maddockdouglas.com
    Mar 5 14:54:49 ichat jabberd/c2s[143]: [7] [::ffff:76.29.0.215, port=39674] disconnect jid=unbound, packets: 0
    Mar 5 15:37:37 ichat jabberd/s2s[145]: [7] [::ffff:74.125.154.87, port=44683] disconnect, packets: 5
    Mar 5 15:58:22 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.85, port=52427] incoming connection
    Mar 5 15:58:22 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.85, port=52427] incoming stream online (id zvk2pr8fzq8s4klvauvacuf5f2qgig6jtuvontqv)
    Mar 5 15:58:22 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.85, port=52427] received dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 15:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 209.85.225.125:5269 (300 seconds to live)
    Mar 5 15:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.155.125:5269 (1800 seconds to live)
    Mar 5 15:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.47.125:5269 (1800 seconds to live)
    Mar 5 15:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.45.125:5269 (1800 seconds to live)
    Mar 5 15:58:23: --- last message repeated 1 time ---
    Mar 5 15:58:23 ichat jabberd/s2s[145]: [7] [::ffff:74.125.52.85, port=52427] incoming route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 16:58:22 ichat jabberd/s2s[145]: [10] [::ffff:74.125.126.83, port=62992] incoming connection
    Mar 5 16:58:22 ichat jabberd/s2s[145]: [10] [::ffff:74.125.126.83, port=62992] incoming stream online (id vkbtpnxey4ycpv6ic5a017mhnm7at68vzbf8nk3o)
    Mar 5 16:58:22 ichat jabberd/s2s[145]: [10] [::ffff:74.125.126.83, port=62992] received dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 16:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 209.85.225.125:5269 (300 seconds to live)
    Mar 5 16:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.45.125:5269 (1800 seconds to live)
    Mar 5 16:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.155.125:5269 (1800 seconds to live)
    Mar 5 16:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.47.125:5269 (1800 seconds to live)
    Mar 5 16:58:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.45.125:5269 (1800 seconds to live)
    Mar 5 16:58:23 ichat jabberd/s2s[145]: [10] [::ffff:74.125.126.83, port=62992] incoming route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 18:00:22 ichat jabberd/s2s[145]: [11] [::ffff:72.14.212.81, port=52803] incoming connection
    Mar 5 18:00:22 ichat jabberd/s2s[145]: [11] [::ffff:72.14.212.81, port=52803] incoming stream online (id 8ta0z4nl27ds9hk2fcvmn9bv05siu6lvzossisu2)
    Mar 5 18:00:22 ichat jabberd/s2s[145]: [11] [::ffff:72.14.212.81, port=52803] received dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 18:00:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 209.85.225.125:5269 (143 seconds to live)
    Mar 5 18:00:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.45.125:5269 (1800 seconds to live)
    Mar 5 18:00:23: --- last message repeated 1 time ---
    Mar 5 18:00:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.155.125:5269 (1800 seconds to live)
    Mar 5 18:00:23 ichat jabberd/resolver[140]: [xmpp-server.tcp.gmail.com] resolved to 74.125.47.125:5269 (1800 seconds to live)
    Mar 5 18:00:23 ichat jabberd/s2s[145]: [12] [74.125.47.125, port=5269] outgoing connection
    Mar 5 18:00:23 ichat jabberd/s2s[145]: [12] [74.125.47.125, port=5269] sending dialback auth request for route 'ichat.maddockdouglas.com/gmail.com'
    Mar 5 18:00:23 ichat jabberd/s2s[145]: [11] [::ffff:72.14.212.81, port=52803] checking dialback verification from gmail.com: sending valid
    Mar 5 18:00:23 ichat jabberd/s2s[145]: [12] [74.125.47.125, port=5269] outgoing route 'ichat.maddockdouglas.com/gmail.com' is now valid
    Mar 5 18:00:23 ichat jabberd/s2s[145]: [11] [::ffff:72.14.212.81, port=52803] incoming route 'ichat.maddockdouglas.com/gmail.com' is now valid

  • Sun Java Portal Server 7.1 Connection Refused

    I am having issues with connecting to Portal Server, I am able to connect to web console and the directory server is running and to amconsole but am unable to connect to the portal server. I keep getting connection refused please help.

    Hi ,
    Do you mean the welcome page that is provided and which point to the three sample portals ? or the login page ?
    The login page can be customized see in the Access Manager Documentation :
    http://docs.sun.com/app/docs/doc/819-4675/6n6qfk0qb?a=view
    Michel

  • How to Create a Single Backend Socket connectivity in a Server Socket Pgm

    Hi Everybody,
    I have a written a Server Socket which connects to back end socket and receiving the data and sending back to the front end. But as per my client requirement i need to create only one socket at the back end. But the code I have written is creating new sockets for each request. Is there any way to use the single client socket connection for all the transactions. I have attached the sample code for the reference.
    import java.io.*;
    import java.net.*;
    import java.nio.ByteBuffer;
    import java.nio.channels.SocketChannel;
    public class serl implements Runnable
    ServerSocket serversocket;
    Socket clientsoc;
    Socket fromclient;
    PrintStream streamtoclient;
    BufferedReader streamfromclient;
    SocketChannel socket_channel=null;
    Thread thread;
    public serl()
    try
    serversocket = new ServerSocket(1001);//create socket
    clientsoc = new Socket("10.100.53.145",200);
    socket_channel = clientsoc.getChannel();
    catch(Exception e)
    System.out.println("Socket could not be created "+e);
    thread=new Thread(this);
    thread.start();
    public void run()
    try
    while(true)
         PrintStream streamtobackend=null;
         BufferedReader streamfrombackend = null;
    fromclient=serversocket.accept();//accept connection fromclient
    streamfromclient=new BufferedReader(new InputStreamReader((fromclient.getInputStream())));
    //create a input stream for the socket
    streamtoclient=new PrintStream(fromclient.getOutputStream());
    //create an a output stream for the socket
    String str=streamfromclient.readLine();
    //read the message sent by client
    System.out.println("Output Input From Vtcpd "+str);
    streamtobackend.print(str);
    streamtobackend = new PrintStream(clientsoc.getOutputStream());
    //create an a output stream for the backend socket
    streamfrombackend = new BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
    //create a input stream for the backend socket
    str=streamfrombackend.readLine();
    System.out.println("Output From Backend Client"+str);
    streamtoclient.println(str);
    }//end of while
    catch(Exception e)
    System.out.println("Exception "+e);
    finally
    try
    fromclient.close();
    catch(Exception e)
    System.out.println("could not close connection "+e);
    public static void main(String ar[])
    new serl();
    }

    Srikandh,
    Create a singelton pattern for you socket ( IP, port, etc..) and each time you read the input stream and write to the output stream, do the following to the socket to reset it in the working thread
    fromclient.getInputStream().mark(0);
    fromclient.getInputStream().reset();Hope this could help
    Regards,
    Alan Mehio
    London,UK

  • How to retain socket connection for multiple requests in java 1.3

    Hi All,
    My problem is to retain client socket connection without opening and closing socket connection for every request.I want to open the socket connection once and send multiple requests one after the other based upon the response over the same socket.Finally I want to close the socket only after completing all my requests and receiving respective responses.I don't want to open and close the socket for each request and response.While at the same time I expect the socket to send each request only after receiving the response for the previous request.
    I am using java 1.3 and I am looking for the solution in same version.
    Please help me .
    Thanx in advance.

    Look at my response to "Telnet to Unix box from Java"
    http://forum.java.sun.com/thread.jsp?forum=31&thread=437231
    on "Java Programming" forum. It does exactly that to run the signon and a command. It would be easy to extend it to do multiple commands.

Maybe you are looking for