Simple chat program

Hi! I would like to implement a simple chat program for iphone (i know that many others still exist). My doubt is about the chat window. I need something like a view or a tableCell to add at the window every time i recieve or write a message, and the view where the conversation happens need to be "slidable"...how can i do this thing? Any suggestion?

There is no standard control that will help you do this. You will most likely want to implement a custom UIScrollView. Within that you will place custom controls programatically to render the conversation or just manage the offsets yourself and draw the text and graphics by overriding the drawRect method.

Similar Messages

  • Need Help with Simple Chat Program

    Hello Guys,
    I'm fairly new to Java and I have a quick question regarding a simple chat program in java. My problem is that I have a simple chat program that runs from its own JFrame etc. Most of you are probably familiar with the code below, i got it from one of my java books. In any case, what I'm attempting to do is integrate this chat pane into a gui that i have created. I attempted to call an instace of the Client class from my gui program so that I can use the textfield and textarea contained in my app, but it will not allow me to do it. Would I need to integrate this code into the code for my Gui class. I have a simple program that contains chat and a game. The code for the Client is listed below.
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    public class Client
    extends JPanel {
    public static void main(String[] args) throws IOException {
    String name = args[0];
    String host = args[1];
    int port = Integer.parseInt(args[2]);
    final Socket s = new Socket(host, port);
    final Client c = new Client(name, s);
    JFrame f = new JFrame("Client : " + name);
    f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    c.shutDown();
    System.exit(0);
    f.setSize(300, 300);
    f.setLocation(100, 100);
    f.setContentPane(c);
    f.setVisible(true);
    private String mName;
    private JTextArea mOutputArea;
    private JTextField mInputField;
    private PrintWriter mOut;
    public Client(final String name, Socket s)
    throws IOException {
    mName = name;
    createUI();
    wireNetwork(s);
    wireEvents();
    public void shutDown() {
    mOut.println("");
    mOut.close();
    protected void createUI() {
    setLayout(new BorderLayout());
    mOutputArea = new JTextArea();
    mOutputArea.setLineWrap(true);
    mOutputArea.setEditable(false);
    add(new JScrollPane(mOutputArea), BorderLayout.CENTER);
    mInputField = new JTextField(20);
    JPanel controls = new JPanel();
    controls.add(mInputField);
    add(controls, BorderLayout.SOUTH);
    mInputField.requestFocus();
    protected void wireNetwork(Socket s) throws IOException {
    mOut = new PrintWriter(s.getOutputStream(), true);
    final String eol = System.getProperty("line.separator");
    new Listener(s.getInputStream()) {
    public void processLine(String line) {
    mOutputArea.append(line + eol);
    mOutputArea.setCaretPosition(
    mOutputArea.getDocument().getLength());
    protected void wireEvents() {
    mInputField.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    String line = mInputField.getText();
    if (line.length() == 0) return;
    mOut.println(mName + " : " + line);
    mInputField.setText("");

    Thanks for ur help!i have moved BufferedReader outside the loop. I dont think i am getting exception as i can c the output once.What i am trying to do is repeat the process which i m getting once.What my method does is first one sends the packet to multicasting group (UDP) and other method receives the packets and prints.

  • A simple chat program

    for a simple chat progam which consists of a server and client, do i have to create 2 sockets to listen on the incoming and outing messengers or let 1 socket do those two things?

    you need one on the client side and another on the server side...
    you use on the client side :
    Socket mySocket=new Socket(ip,port);and on the server side:
    Socket mySocket=sSocket.accept(); //sSocket is an instance of ServerSocket

  • Windows impliementation of simple chat program

    import java.io.*;
    import java.net.*;
    import java.util.Scanner;
    public class TCPClient {
       public static void main(String args[]) throws Exception {
         String fromServer;
         String toClient;
         Scanner scanner = new Scanner(System.in);
         BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
         Socket clientSocket = new Socket("plato", 5454); //Port number
         DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
         BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
         System.out.println("<---Connection Established, type 'QUIT' to end this conversation.--->");
         //A message notifying both users about the connection.
         while (true) {
           fromServer = inFromServer.readLine(); //Read message from server.
           System.out.println(fromServer); //Print out the message from the server.
           System.out.println("Enter a message:"); //Server prompts to type a message to Client.
           toClient = scanner.nextLine(); //The message gets read through the Scanner.
           if (toClient.equals("QUIT")) {
             System.out.println("Chat Terminated"); //A message showing that the conversation has ended.
             System.exit(0); //Then the Client closes the conversation.
           } else {
             outToServer.writeBytes("FROM CLIENT: " + toClient + '\n'); //Send the message to Server.
    import java.io.*;
    import java.net.*;
    import java.util.Scanner;
    public class TCPServer {
       public static void main(String args[]) throws Exception {
         String fromClient;
          String fromServer;
          Scanner scanner = new Scanner(System.in);
          ServerSocket welcomeSocket = new ServerSocket(5454); //Port Number
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream toClient = new DataOutputStream(connectionSocket.getOutputStream());
          System.out.println("<---Connection Established--->"); //A message notifying both users about the connection.
          while (true) { //An infinite loop letting the conversation go on until Client types in "QUIT".
            System.out.println("Enter a message:"); //Client prompts to type a message to Server.
            fromServer = scanner.nextLine(); //The message gets read through the Scanner.
            toClient.writeBytes("FROM SERVER: " + fromServer + '\n'); //It then sends it to the Client.
            fromClient = inFromClient.readLine(); //Read message from the Client.
            System.out.println(fromClient); //Print out the message from the Client.
    }What do I need to change in order get this to work with windows command prompt cos I have no idea myself. Bare in mind also that I'll be using this at home to test stuff. It work at uni with unix but department is closed for the holidays.
    Thanks

    Thanks
    I've got another question
    import java.io.*;
    import java.net.*;
    import java.util.Scanner;
    import java.math.*;
    public class TCPServer {
       public static void main(String args[]) throws Exception {
         String fromClient;
          String fromServer;
          Scanner scanner = new Scanner(System.in);
          ServerSocket welcomeSocket = new ServerSocket(80); //Port Number
          Socket connectionSocket = welcomeSocket.accept();
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
          DataOutputStream toClient = new DataOutputStream(connectionSocket.getOutputStream());
          System.out.println("<---Connection Established--->"); //A message notifying both users about the connection.
          BigInteger b1 = new BigInteger("41241");
          BigInteger b2 = new BigInteger("29592");
          BigInteger b3 = new BigInteger("69311");
          byte [] a = null;
          a = b1.toByteArray();
          byte [] b = null;
          b = b2.toByteArray();
          byte [] c = null;
          c = b3.toByteArray();
          toClient.write(a, 0, a.length);
          toClient.flush();
          toClient.write(b, 0, b.length);
          toClient.flush();
          toClient.write(c, 0, c.length);
          toClient.flush();
          while (true) { //An infinite loop letting the conversation go on until Client types in "QUIT".
            System.out.println("Enter a message:"); //Client prompts to type a message to Server.
            fromServer = scanner.nextLine(); //The message gets read through the Scanner.
            toClient.writeBytes("FROM SERVER: " + fromServer + '\n'); //It then sends it to the Client.
            fromClient = inFromClient.readLine(); //Read message from the Client.
            System.out.println(fromClient); //Print out the message from the Client.
    }Currently I'm sending 3 BigInt numbers in the form of a Byte array.
    When I run the TCPServer then the TCPClient, the first message I type from the server side displays some weird looking characters. Im guessing these are the numbers but how can I from the TCPClient side extract these weird looking characters as BigInts and store them (which I can do in a BigInt array or something).
    Thanks

  • Chat program in release 4.7c

    hi guys,
    I was wondering how one can create a chat program in abap. As its possible in Java & .Net why an abaper under estimate himself. Now here imagine a simple chat program where one can send some text from his SAP GUI which will appear on others SAP GUI and viceversa. Dont think about some messangers like yahoo or gtalk.(dont over estimate being an abaper)
    So i developed two programs one to send text & other to receive text. Send prg. is module pool and receive prg. is a simple report which has timer class which gets data from table every second so user dont have to press any button to receive the message.
    To start chat you have to run both programs in your GUI where from send program you enter your name in one text field and your message in other text field by pressing enter it gets update in table field(not every time it insert new record, it simply update previous so table size would not increase). As the person with whoem you are chatting is also running both programs, your message appears in 2nd program on his GUI & yours also. followed by your name.
    Both chat programs works fine with more then two users also. i tried to combine both program in one screen so user can send & receive chat from one screen. but due to timer class used, its not possible as receive program keeps refreshing for every 1 second.
    so i am wondering is thier any way to run one modulepool program & one report in a single screen. some thing like screen splitting or docking???
    you are welcome to share your ideas regarding chat in ABAP/4(release 4.7)
    Regards,
    SUDHIR MANJAREKAR

    Yes, thats right. There are few ABAP codes which you can find in the net and can improvise on that.
    The program displays list of all users who are currently active on a list.
    You can select user and select press button on the application tool bar to send a message.
    Concerns here are: 1. The receiver cannot reply from the same popup. He has to run the program, select the user who has send message and reply. 2. You will not be able to see the entire message log.
    For logging messages you can try creating standard text for tracking dialog between any two user and something of that sort.
    regards,
    S. Chandramouli.

  • GUI for chat program

    Hi everyone,
    I'm writing a simple chat program as a assignment at my Uni. I get stucked with the client GUI. I want to create a GUI like that of Yahoo messenger which has a list of connected users displayed on the GUI. When u double click on the name of the user, u will get connected to that user. I have no idea about creating a GUI list like this one. Can anybody help me with this? Thanks in advance!

    There are many tutorials on this site; check the "tutorials" link on the column on the left.
    Here are ones about GUIs:
    http://developer.java.sun.com/developer/onlineTraining/GUI/
    I'd suggest skipping over any tutorials prior to JDK 1.1 or even 1.2.
    Read more recent ones. There have been significant improvements, especially w.r.t. event handling, between 1.0 and 1.1.

  • Please help (Simple chat programme)

    I made a simple chat programme.
    It has a server object and it can handle several client.
    It is working properly and can use to chat.
    I have some problems. can you please help me.
    1.What is the best method to read input and outputStreams
    I have used inputStream.readUTF()/outputStream.writeUTF() methods and
    also I have used bufferedReader.readLine()/Printwriter.println() methods.
    I don't know about other methods.So please tell me what is the best and new out of these two.
    And are there any method which is better than these two.
    2.Is there any way to get more details from input and output streams
    Here more details means Fontcolor,Size etc;
    by now I'm adding them in to my output streams and filtering them when rea input stream.
    I'm getting other details(Fontcolor,Size) and add them all to a string.
    that means if client type "hi" my string will be something like this
    "12ff0000hi".
    When read the input stream i make a char[] and take first 2 chars to integer next six to a string and rest
    to another string.
    I think now you can understand my concept. So I'll not tell every thing.(if you want i can fully describe it)
    I' feeling this is very bad way to do that kind of work.
    Am i correct?
    so can you give me some hints or examples to do such kind of things.

    Here's a simple DataInputStream program that talks to itself. It runs the server as a seperate thread.
    import java.io.*;
    import java.net.*;
    public class DataXfer
            private int port = 5050;
            private String address="127.0.0.1";
            public static void main(String args[])
                    new DataXfer().startup();
            // run the server code as a thread and then run the client code
            private void startup()
                    new Thread(new Runnable(){public void run(){listen();}}).start(); // start server thread
                    synchronized(this){
                            try{wait();}catch(InterruptedException ie){}    // wait until its ready
                    connect();                                      // do client stuff     
            private void listen()
                    ServerSocket ss = null;
                    Socket us = null;
                    boolean running = true;
                    try{
                            System.out.println("Listening on port "+port);
                            synchronized(this){notify();}               // tell client we're ready
                            ss = new ServerSocket(port);    // listen for incoming connection
                            us = ss.accept();
                            ss.close();
                            ss = null;
                            DataInputStream dis = new DataInputStream(us.getInputStream());
                            try{
                                    while(running){
                                            int len = dis.readShort();      // read the count
                                            byte [] ba = new byte[len];
                                            int rlen = dis.read(ba,0,len);  // read the data
                                            System.out.println("len="+len+" read length="+rlen);
                                            if(rlen < len){
                                                    us.close();
                                                    running = false;
                                            else{
                                                    for(int j = 0; j<rlen; j++)System.out.print(ba[j]+" ");
                                                    System.out.println("");
                            catch(EOFException ee){System.out.println("EOF");}
                    catch(IOException ie){
                            ie.printStackTrace();
                            System.exit(0);
                    finally{
                            if(ss != null)try{ss.close();}catch(IOException se){}
                            if(us != null)try{us.close();}catch(IOException ue){}
            private void connect()
                    Socket us=null;
                    byte [] ba = new byte[31];
                    for(byte i = 0; i<ba.length; i++)ba=i;
    try{
    System.out.println("Connecting to "+address+":"+port);
    us = new Socket(address, port); // make connection
    System.out.println("Connected");
    DataOutputStream dos = new DataOutputStream(us.getOutputStream());
    for(int j = 0; j<ba.length;j+=10){
    dos.writeShort(j); // write the count
    dos.write(ba,0,j); // write the data
    System.out.println("sent "+j+" bytes");
    try{Thread.sleep(1000);}catch(InterruptedException ie){}
    catch(IOException ie){ie.printStackTrace();}
    finally{
    if(us != null)try{us.close();}catch(IOException ue){}
    For an example of a chat program using NIO see my NIO Server Example. That example is neither short nor simple.

  • VERY simple chat

    I've been playing around with network programming, and I'm trying to create a simple chat system. I've already got the client side done, but I'm wondering how I should do the chat server.
    I wanted the server to be something in the middle. Say I have two chat clients, I want the server to be running anonymously in the background relaying the messages back and forth. I'm just having problems figuring out how that I would get the server to register more than one client, and rely the message to the other clients.
    Could you guys give me some comments/suggestions on this? Does my idea sound dumb?

    Could you guys give me some comments/suggestions on
    this? Does my idea sound dumb?Not at all. Check these out for examples:
    http://www-106.ibm.com/developerworks/edu/j-dw-javachat-i.html
    http://access1.sun.com/codesamples/J2SE-MultiCastSockets.html
    http://www.cs.ucsb.edu/~cappello/290i/lectures/rmi/chatNew.html

  • SSL simple chat

    Hallo,
    I did SSL simple chat, but something is wrong. This program is cennect to another same program(on localhost has diferent ports number). When send thread is weak up, NetBeans write this error: SEVERE: null
    java.net.UnknownHostException: java.
    I work with SSL fist time, I don´t know where I is error. I was inspire on this web side stilius.net/java/java_ssl.php and I use same keytool command. But I don´t know taht, I right use parametrs becouse I have server part and client part i one program.
    Could you check my code.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.OutputStreamWriter;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.net.ssl.SSLServerSocket;
    import javax.net.ssl.SSLServerSocketFactory;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    * SslReverseEchoer.java
    * Copyright (c) 2005 by Dr. Herong Yang
    public class Main {
       public static void main(String[] args) {
           String addressIP;
           if(args.length==0)
                addressIP="127.0.0.1";
           else
               addressIP=args[0];
          ReciveThread recive = new ReciveThread();
          SendThread send = new SendThread(addressIP);
          recive.recive.start();
          send.send.start();
    class ReciveThread implements Runnable
    {   Thread recive;
        public ReciveThread()
            recive = new Thread(this,"Recive thread");
        public void run()
            try {
                SSLServerSocketFactory sslFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
                SSLServerSocket sslServer = (SSLServerSocket) sslFactory.createServerSocket(5000);
                SSLSocket ssl = (SSLSocket) sslServer.accept();
                System.out.println("Adresa hostitele:"+ssl.getInetAddress().getHostName());
                while(true){
                    BufferedReader buffRead = new BufferedReader(new InputStreamReader(ssl.getInputStream()));
                    String line = null;
                    while((line = buffRead.readLine())!=null)
                        System.out.println("Recive data:"+line);
                        System.out.flush();
            } catch (IOException ex) {
    class SendThread implements Runnable
    {   Thread send;
        private String addressIP;
        public SendThread(String ip)
            this.addressIP=ip;
            send = new Thread(this,"Send thread");
        public void run()
            try {
                Thread.sleep(10000);
                SSLSocketFactory sslFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
                SSLSocket ssl = (SSLSocket) sslFactory.createSocket(this.addressIP,4000);
                BufferedReader buffKeyboard = new BufferedReader(new InputStreamReader(System.in));
                OutputStream outputStream = ssl.getOutputStream();
                BufferedWriter Buffwriter = new BufferedWriter(new OutputStreamWriter(outputStream));
                String radek = null;
                while((radek = buffKeyboard.readLine())!=null)
                    Buffwriter.write(radek+'\n');
                    Buffwriter.newLine();
                    Buffwriter.flush();
                    System.out.println("Posilana data:"+radek);
            } catch (InterruptedException ex) {
                Logger.getLogger(SendThread.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(SendThread.class.getName()).log(Level.SEVERE, null, ex);
    }  

    OK i cut while(true){. This error write on this line: SSLSocket ssl = (SSLSocket) sslFactory.createSocket(this.addressIP,4000); . I think problem is somewhere in creating listen socket or wrong using parametrs for running programs. How can i put this:
    First copy certificate file that you created before into working directory and run server with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:
    java -Djavax.net.ssl.keyStore=mySrvKeystore -Djavax.net.ssl.keyStorePassword=123456 EchoServer
    And now again copy certificate file that you created before into working directory and run client with these parameters (notice that you have to change keyStore name and/or trustStrorePassword if you specified different options creating certificate:
    java -Djavax.net.ssl.trustStore=mySrvKeystore -Djavax.net.ssl.trustStorePassword=123456 EchoClient
    If i use server and client together in one program?

  • Voice chat program

    After a few days work, I have completed the mian voice chat program. I know there are so many people like me that wants that. I post these program. i will complete gui work later. and there is a problem in the program. if the speaking one do not speak for a while, the listening client will hear noise. Can some one help me.
    package com.longshine.voice;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Server
    // The ServerSocket we'll use 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();
    final int bufSize = 16384;
    //current speak_man
    private int speakman=-1;
    // Constructor and while-accept loop all in one.
    public Server( int port ) throws IOException {
    // All we have to do is listen
    listen( port );
    private void listen( int port ) throws IOException {
    // Create the ServerSocket
    ss = new ServerSocket( port );
    // Tell the world we're ready to go
    System.out.println( "Listening on "+ss );
    // Keep accepting connections forever
    while (true) {
    // Grab the next incoming connection
    Socket s = ss.accept();
    // Tell the world we've got it
    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 VoiceServer( 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( byte[] voice ,Socket socket) {
    // We synchronize on this because another thread might be
    // calling removeConnection() and this would screw us up
    // as we tried to walk through the list
    synchronized( outputStreams ) {
    // For each client ...
    for (Enumeration e = outputStreams.keys(); e.hasMoreElements(); ) {
    // ... get the output stream ...
    Socket tmp=(Socket)e.nextElement();
    if(!tmp.equals(socket))
    try {
    DataOutputStream dout = new DataOutputStream(tmp.getOutputStream());
    // ... and send the message
    dout.write(voice,0,44096);
    dout.flush();
    } 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 ) {
    // Synchronize so we don't mess up sendToAll() while it walks
    // down the list of all output streamsa
    synchronized( outputStreams ) {
    // Tell the world
    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] );
    // Create a Server object, which will automatically begin
    // accepting connections.
    new Server( port );
    package com.longshine.voice;
    import java.net.*;
    import java.io.*;
    import java.sql.*;
    import java.io.*;
    import java.net.*;
    public class VoiceServer extends Thread
    // The Server that spawned us
    private Server server;
    final int bufSize = 16384;
    // The Socket connected to our client
    private Socket socket;
    // Constructor.
    public VoiceServer( 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() );
    byte[] voice=new byte[44096];
    // Over and over, forever ...
    while (true) {
    // ... read the next message ...
    // int bytes = din.read(voice,0,44096);
    int bytes = din.read(voice);
    // ... and have the server send it to all clients
    server.sendToAll(voice,socket);
    } catch( EOFException ie ) {
    // This doesn't need an error message
    } catch( IOException ie ) {
    // This does; tell the world!
    ie.printStackTrace();
    } finally {
    // The connection is closed for one reason or another,
    // so have the server dealing with it
    server.removeConnection( socket );
    package com.longshine.voice;
    import java.io.*;
    import java.net.*;
    public class Client {
    private String host="";
    private String port="";
    private Socket socket;
    private DataOutputStream dout;
    private DataInputStream din;
    private Capture capture=null;
    private Play play=null;
    public Client(String host,String port) {
    this.host=host;
    this.port=port;
    public void init()
    try
    socket = new Socket( host, Integer.parseInt(port));
    din = new DataInputStream( socket.getInputStream() );
    dout = new DataOutputStream( socket.getOutputStream());
    capture=new Capture(dout);
    play=new Play(din);
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args) {
    Client client = new Client("172.18.220.176","5678");
    client.init();
    if(args[0].equalsIgnoreCase("say"))
    client.capture.start();
    if(args[0].equalsIgnoreCase("hear"))
    client.play.start();
    package com.longshine.voice;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    import javax.sound.sampled.*;
    import java.text.*;
    import java.net.*;
    public class Play implements Runnable {
    SourceDataLine line;
    Thread thread;
    String errStr=null;
    DataInputStream in=null;
    AudioInputStream audioInputStream;
    final int bufSize = 16384;
    int duration=0;
    public Play(DataInputStream in)
    this.in=in;
    public void start() {
    errStr = null;
    thread = new Thread(this);
    thread.setName("Playback");
    thread.start();
    public void stop() {
    thread = null;
    private void shutDown(String message) {
    if ((errStr = message) != null) {
    System.err.println(errStr);
    if (thread != null) {
    thread = null;
    public void createAudioInputStream() {
    if (in != null ) {
    try {
    errStr = null;
    java.io.BufferedInputStream oin = new java.io.BufferedInputStream(in);
    audioInputStream = AudioSystem.getAudioInputStream(oin);
    } catch (Exception ex) {
    ex.printStackTrace();
    } else {
    public void run() {
    // reload the file if loaded by file
    if (in != null) {
    // createAudioInputStream();
    // make sure we have something to play
    // if (audioInputStream == null) {
    // shutDown("No loaded audio to play back");
    // return;
    // reset to the beginnning of the stream
    // try {
    // audioInputStream.reset();
    // } catch (Exception e) {
    // shutDown("Unable to reset the stream\n" + e);
    // return;
    // get an AudioInputStream of the desired format for playback
    AudioFormat format = getFormat();
    audioInputStream=new AudioInputStream(in, format, AudioSystem.NOT_SPECIFIED);
    AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);
    if (playbackInputStream == null) {
    shutDown("Unable to convert stream of format " + audioInputStream + " to format " + format);
    return;
    // define the required attributes for our line,
    // and make sure a compatible line is supported.
    DataLine.Info info = new DataLine.Info(SourceDataLine.class,
    format);
    if (!AudioSystem.isLineSupported(info)) {
    shutDown("Line matching " + info + " not supported.");
    return;
    // get and open the source data line for playback.
    try {
    line = (SourceDataLine) AudioSystem.getLine(info);
    line.open(format, bufSize);
    } catch (LineUnavailableException ex) {
    shutDown("Unable to open the line: " + ex);
    return;
    // play back the captured audio data
    int frameSizeInBytes = format.getFrameSize();
    int bufferLengthInFrames = line.getBufferSize() / 8;
    int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
    byte[] data = new byte[bufferLengthInBytes];
    int numBytesRead = 0;
    // start the source data line
    line.start();
    while (thread != null) {
    try {
    if ((numBytesRead = playbackInputStream.read(data)) == -1) {
    break;
    int numBytesRemaining = numBytesRead;
    while (numBytesRemaining > 0 ) {
    numBytesRemaining -= line.write(data, 0, numBytesRemaining);
    } catch (Exception e) {
    shutDown("Error during playback: " + e);
    break;
    // we reached the end of the stream. let the data play out, then
    // stop and close the line.
    if (thread != null) {
    line.drain();
    line.stop();
    line.close();
    line = null;
    shutDown(null);
    public AudioFormat getFormat() {
    AudioFormat.Encoding encoding = AudioFormat.Encoding.ULAW;
    String encString = "linear";
    float rate = Float.valueOf("44100").floatValue();
    int sampleSize = 16;
    String signedString = "signed";
    boolean bigEndian = true;
    int channels = 2;
    if (encString.equals("linear")) {
    if (signedString.equals("signed")) {
    encoding = AudioFormat.Encoding.PCM_SIGNED;
    } else {
    encoding = AudioFormat.Encoding.PCM_UNSIGNED;
    } else if (encString.equals("alaw")) {
    encoding = AudioFormat.Encoding.ALAW;
    return new AudioFormat(encoding, rate, sampleSize,
    channels, (sampleSize/8)*channels, rate, bigEndian);
    } // End class Playback
    package com.longshine.voice;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    import javax.sound.sampled.*;
    import java.text.*;
    import java.net.*;
    public class Capture implements Runnable {
    TargetDataLine line;
    Thread thread;
    String errStr=null;
    DataOutputStream out=null;
    AudioInputStream audioInputStream;
    final int bufSize = 16384;
    int duration=0;
    public Capture(DataOutputStream out)
    this.out=out;
    public void start() {
    errStr = null;
    thread = new Thread(this);
    thread.setName("Playback");
    thread.start();
    public void stop() {
    thread = null;
    private void shutDown(String message) {
    if ((errStr = message) != null) {
    System.out.println(errStr);
    if (thread != null) {
    thread = null;
    public AudioFormat getFormat() {
    AudioFormat.Encoding encoding = AudioFormat.Encoding.ULAW;
    String encString = "linear";
    float rate = Float.valueOf("44100").floatValue();
    int sampleSize = 16;
    String signedString = "signed";
    boolean bigEndian = true;
    int channels = 2;
    if (encString.equals("linear")) {
    if (signedString.equals("signed")) {
    encoding = AudioFormat.Encoding.PCM_SIGNED;
    } else {
    encoding = AudioFormat.Encoding.PCM_UNSIGNED;
    } else if (encString.equals("alaw")) {
    encoding = AudioFormat.Encoding.ALAW;
    return new AudioFormat(encoding, rate, sampleSize,
    channels, (sampleSize/8)*channels, rate, bigEndian);
    public void run() {
    duration = 0;
    audioInputStream = null;
    // define the required attributes for our line,
    // and make sure a compatible line is supported.
    AudioFormat format = getFormat();
    DataLine.Info info = new DataLine.Info(TargetDataLine.class,
    format);
    if (!AudioSystem.isLineSupported(info)) {
    shutDown("Line matching " + info + " not supported.");
    return;
    // get and open the target data line for capture.
    try {
    line = (TargetDataLine) AudioSystem.getLine(info);
    line.open(format, line.getBufferSize());
    } catch (LineUnavailableException ex) {
    shutDown("Unable to open the line: " + ex);
    return;
    } catch (SecurityException ex) {
    shutDown(ex.toString());
    return;
    } catch (Exception ex) {
    shutDown(ex.toString());
    return;
    // play back the captured audio data
    int frameSizeInBytes = format.getFrameSize();
    int bufferLengthInFrames = line.getBufferSize() / 8;
    int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
    byte[] data = new byte[bufferLengthInBytes];
    int numBytesRead;
    line.start();
    try
    while (thread != null) {
    if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
    break;
    if(data.length>0)
    out.write(data, 0, numBytesRead);
    out.flush();
    catch (Exception e)
    e.printStackTrace();
    // we reached the end of the stream. stop and close the line.
    line.stop();
    line.close();
    line = null;
    // stop and close the output stream
    try {
    out.flush();
    out.close();
    } catch (IOException ex) {
    ex.printStackTrace();
    } // End class Capture

    After a few days work, I have completed the mian voice chat program. I know there are so many people like me that wants that. I post these program. i will complete gui work later. and there is a problem in the program. if the speaking one do not speak for a while, the listening client will hear noise. Can some one help me.
    package com.longshine.voice;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Server
    // The ServerSocket we'll use 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();
    final int bufSize = 16384;
    //current speak_man
    private int speakman=-1;
    // Constructor and while-accept loop all in one.
    public Server( int port ) throws IOException {
    // All we have to do is listen
    listen( port );
    private void listen( int port ) throws IOException {
    // Create the ServerSocket
    ss = new ServerSocket( port );
    // Tell the world we're ready to go
    System.out.println( "Listening on "+ss );
    // Keep accepting connections forever
    while (true) {
    // Grab the next incoming connection
    Socket s = ss.accept();
    // Tell the world we've got it
    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 VoiceServer( 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( byte[] voice ,Socket socket) {
    // We synchronize on this because another thread might be
    // calling removeConnection() and this would screw us up
    // as we tried to walk through the list
    synchronized( outputStreams ) {
    // For each client ...
    for (Enumeration e = outputStreams.keys(); e.hasMoreElements(); ) {
    // ... get the output stream ...
    Socket tmp=(Socket)e.nextElement();
    if(!tmp.equals(socket))
    try {
    DataOutputStream dout = new DataOutputStream(tmp.getOutputStream());
    // ... and send the message
    dout.write(voice,0,44096);
    dout.flush();
    } 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 ) {
    // Synchronize so we don't mess up sendToAll() while it walks
    // down the list of all output streamsa
    synchronized( outputStreams ) {
    // Tell the world
    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] );
    // Create a Server object, which will automatically begin
    // accepting connections.
    new Server( port );
    package com.longshine.voice;
    import java.net.*;
    import java.io.*;
    import java.sql.*;
    import java.io.*;
    import java.net.*;
    public class VoiceServer extends Thread
    // The Server that spawned us
    private Server server;
    final int bufSize = 16384;
    // The Socket connected to our client
    private Socket socket;
    // Constructor.
    public VoiceServer( 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() );
    byte[] voice=new byte[44096];
    // Over and over, forever ...
    while (true) {
    // ... read the next message ...
    // int bytes = din.read(voice,0,44096);
    int bytes = din.read(voice);
    // ... and have the server send it to all clients
    server.sendToAll(voice,socket);
    } catch( EOFException ie ) {
    // This doesn't need an error message
    } catch( IOException ie ) {
    // This does; tell the world!
    ie.printStackTrace();
    } finally {
    // The connection is closed for one reason or another,
    // so have the server dealing with it
    server.removeConnection( socket );
    package com.longshine.voice;
    import java.io.*;
    import java.net.*;
    public class Client {
    private String host="";
    private String port="";
    private Socket socket;
    private DataOutputStream dout;
    private DataInputStream din;
    private Capture capture=null;
    private Play play=null;
    public Client(String host,String port) {
    this.host=host;
    this.port=port;
    public void init()
    try
    socket = new Socket( host, Integer.parseInt(port));
    din = new DataInputStream( socket.getInputStream() );
    dout = new DataOutputStream( socket.getOutputStream());
    capture=new Capture(dout);
    play=new Play(din);
    catch(Exception e)
    e.printStackTrace();
    public static void main(String[] args) {
    Client client = new Client("172.18.220.176","5678");
    client.init();
    if(args[0].equalsIgnoreCase("say"))
    client.capture.start();
    if(args[0].equalsIgnoreCase("hear"))
    client.play.start();
    package com.longshine.voice;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    import javax.sound.sampled.*;
    import java.text.*;
    import java.net.*;
    public class Play implements Runnable {
    SourceDataLine line;
    Thread thread;
    String errStr=null;
    DataInputStream in=null;
    AudioInputStream audioInputStream;
    final int bufSize = 16384;
    int duration=0;
    public Play(DataInputStream in)
    this.in=in;
    public void start() {
    errStr = null;
    thread = new Thread(this);
    thread.setName("Playback");
    thread.start();
    public void stop() {
    thread = null;
    private void shutDown(String message) {
    if ((errStr = message) != null) {
    System.err.println(errStr);
    if (thread != null) {
    thread = null;
    public void createAudioInputStream() {
    if (in != null ) {
    try {
    errStr = null;
    java.io.BufferedInputStream oin = new java.io.BufferedInputStream(in);
    audioInputStream = AudioSystem.getAudioInputStream(oin);
    } catch (Exception ex) {
    ex.printStackTrace();
    } else {
    public void run() {
    // reload the file if loaded by file
    if (in != null) {
    // createAudioInputStream();
    // make sure we have something to play
    // if (audioInputStream == null) {
    // shutDown("No loaded audio to play back");
    // return;
    // reset to the beginnning of the stream
    // try {
    // audioInputStream.reset();
    // } catch (Exception e) {
    // shutDown("Unable to reset the stream\n" + e);
    // return;
    // get an AudioInputStream of the desired format for playback
    AudioFormat format = getFormat();
    audioInputStream=new AudioInputStream(in, format, AudioSystem.NOT_SPECIFIED);
    AudioInputStream playbackInputStream = AudioSystem.getAudioInputStream(format, audioInputStream);
    if (playbackInputStream == null) {
    shutDown("Unable to convert stream of format " + audioInputStream + " to format " + format);
    return;
    // define the required attributes for our line,
    // and make sure a compatible line is supported.
    DataLine.Info info = new DataLine.Info(SourceDataLine.class,
    format);
    if (!AudioSystem.isLineSupported(info)) {
    shutDown("Line matching " + info + " not supported.");
    return;
    // get and open the source data line for playback.
    try {
    line = (SourceDataLine) AudioSystem.getLine(info);
    line.open(format, bufSize);
    } catch (LineUnavailableException ex) {
    shutDown("Unable to open the line: " + ex);
    return;
    // play back the captured audio data
    int frameSizeInBytes = format.getFrameSize();
    int bufferLengthInFrames = line.getBufferSize() / 8;
    int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
    byte[] data = new byte[bufferLengthInBytes];
    int numBytesRead = 0;
    // start the source data line
    line.start();
    while (thread != null) {
    try {
    if ((numBytesRead = playbackInputStream.read(data)) == -1) {
    break;
    int numBytesRemaining = numBytesRead;
    while (numBytesRemaining > 0 ) {
    numBytesRemaining -= line.write(data, 0, numBytesRemaining);
    } catch (Exception e) {
    shutDown("Error during playback: " + e);
    break;
    // we reached the end of the stream. let the data play out, then
    // stop and close the line.
    if (thread != null) {
    line.drain();
    line.stop();
    line.close();
    line = null;
    shutDown(null);
    public AudioFormat getFormat() {
    AudioFormat.Encoding encoding = AudioFormat.Encoding.ULAW;
    String encString = "linear";
    float rate = Float.valueOf("44100").floatValue();
    int sampleSize = 16;
    String signedString = "signed";
    boolean bigEndian = true;
    int channels = 2;
    if (encString.equals("linear")) {
    if (signedString.equals("signed")) {
    encoding = AudioFormat.Encoding.PCM_SIGNED;
    } else {
    encoding = AudioFormat.Encoding.PCM_UNSIGNED;
    } else if (encString.equals("alaw")) {
    encoding = AudioFormat.Encoding.ALAW;
    return new AudioFormat(encoding, rate, sampleSize,
    channels, (sampleSize/8)*channels, rate, bigEndian);
    } // End class Playback
    package com.longshine.voice;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    import javax.sound.sampled.*;
    import java.text.*;
    import java.net.*;
    public class Capture implements Runnable {
    TargetDataLine line;
    Thread thread;
    String errStr=null;
    DataOutputStream out=null;
    AudioInputStream audioInputStream;
    final int bufSize = 16384;
    int duration=0;
    public Capture(DataOutputStream out)
    this.out=out;
    public void start() {
    errStr = null;
    thread = new Thread(this);
    thread.setName("Playback");
    thread.start();
    public void stop() {
    thread = null;
    private void shutDown(String message) {
    if ((errStr = message) != null) {
    System.out.println(errStr);
    if (thread != null) {
    thread = null;
    public AudioFormat getFormat() {
    AudioFormat.Encoding encoding = AudioFormat.Encoding.ULAW;
    String encString = "linear";
    float rate = Float.valueOf("44100").floatValue();
    int sampleSize = 16;
    String signedString = "signed";
    boolean bigEndian = true;
    int channels = 2;
    if (encString.equals("linear")) {
    if (signedString.equals("signed")) {
    encoding = AudioFormat.Encoding.PCM_SIGNED;
    } else {
    encoding = AudioFormat.Encoding.PCM_UNSIGNED;
    } else if (encString.equals("alaw")) {
    encoding = AudioFormat.Encoding.ALAW;
    return new AudioFormat(encoding, rate, sampleSize,
    channels, (sampleSize/8)*channels, rate, bigEndian);
    public void run() {
    duration = 0;
    audioInputStream = null;
    // define the required attributes for our line,
    // and make sure a compatible line is supported.
    AudioFormat format = getFormat();
    DataLine.Info info = new DataLine.Info(TargetDataLine.class,
    format);
    if (!AudioSystem.isLineSupported(info)) {
    shutDown("Line matching " + info + " not supported.");
    return;
    // get and open the target data line for capture.
    try {
    line = (TargetDataLine) AudioSystem.getLine(info);
    line.open(format, line.getBufferSize());
    } catch (LineUnavailableException ex) {
    shutDown("Unable to open the line: " + ex);
    return;
    } catch (SecurityException ex) {
    shutDown(ex.toString());
    return;
    } catch (Exception ex) {
    shutDown(ex.toString());
    return;
    // play back the captured audio data
    int frameSizeInBytes = format.getFrameSize();
    int bufferLengthInFrames = line.getBufferSize() / 8;
    int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
    byte[] data = new byte[bufferLengthInBytes];
    int numBytesRead;
    line.start();
    try
    while (thread != null) {
    if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
    break;
    if(data.length>0)
    out.write(data, 0, numBytesRead);
    out.flush();
    catch (Exception e)
    e.printStackTrace();
    // we reached the end of the stream. stop and close the line.
    line.stop();
    line.close();
    line = null;
    // stop and close the output stream
    try {
    out.flush();
    out.close();
    } catch (IOException ex) {
    ex.printStackTrace();
    } // End class Capture

  • "Assertion failed" error when executing a simple UCI program

    I am using a simple UCI program (tt1.c) with Xmath version 7.0.1 on Sloaris 2.8 that performs the followings:
    - Start Xmath701
    - Sleep 10 Seconds
    - Load a sysbuild model
    - Stop Xmath
    I am calling the uci executable using the following command:
    > /usr/local/apps/matrixx-7.0.1/bin/xmath -call tt1 &
    In this way everything works fine and the following printouts from the program are produced.
    --------- uci printout ----------
    ## Starting Xmath 701
    ## sleep 10 seconds
    ## load "case_h_cs_ds.xmd";
    ## Stopping Xmath 701
    All the processes (tt1, XMATH, xmath_mon, and sysbld) terminate correctly.
    The problem occurs if the 10 second wait after starting xmath is omitted:
    - Start Xmath701
    - Load a sysbuild model
    - Stop Xmath
    This results to the following printouts:
    --------- uci printout ----------
    ## Starting Xmath 701
    ## load "case_h_cs_ds.xmd";
    Assertion failed: file "/vob1/xm/ipc/ipc.cxx", line 420 errno 0.
    Note that the last line is not produced by the uci program and the tt1 did not
    finish (the printout before stopping xmath "## Stopping Xmath 701" was
    not produced).
    A call to the unix "ps -ef" utility shows that none of the related process has been terminated:
    fs085312 27631 20243 0 10:45:29 pts/27 0:00 tt1
    fs085312 27643 1 0 10:45:30 ? 0:00 /usr/local/apps/matrixx-7.0.1/solaris_mx_70.1/xmath/bin/xmath_mon /usr/local/app
    fs085312 27641 27631 0 10:45:30 ? 0:01 /usr/local/apps/matrixx-7.0.1/solaris_mx_70.1/xmath/bin/XMATH 142606339, 0x8800
    fs085312 25473 25446 0 10:45:33 ? 0:01 sysbld ++ 19 4 7 6 5 8 9 0 25446 ++
    The questions are as follows:
    1- What is "Assertion failed: file "/vob1/xm/ipc/ipc.cxx", line 420 errno 0" and why is that produced?
    2- Should the UCI program waits for end of sysbld initialization before issuing commands?
    3- If the answer to the above question is yes, is there a way to check the termination of sysbld initialization?
    Thanks in advance for you help.
    Attachments:
    tt1.c ‏1 KB

    I tracked down the problem and it is a race condition between the many processes being started up. A smaller delay should also solve the problem. Or, maybe do something else before the first 'load'. The 'load' command tries to launch systembuild and causes the race condition.

  • Weblogic error while deplying a simple servlet program

    Hi This is a very simple servlet program.
    I am trying to deploy it on the weblogic server but i get this error as follow
    Unable to access the selected application.
    *javax.enterprise.deploy.spi.exceptions.InvalidModuleException: [J2EE Deployment SPI:260105]Failed to create*
    DDBeanRoot for application, 'E:\AqanTech\WebApp1\myApp.war'.
    I have checked everything, right from my code to my web.xml file. I have used a build.bat file to build my war file.
    PLEASE HELP ME TO SOLVE THIS HUGE PROBLEM OF MINE ?
    Thanks,
    Shoeb

    Hi,
    The J2EE Error code siply suggest that there is something wrong in your Deployment Descriptors...
    Can u please post the XML files available inside your "WEB-INF" directory?
    Thanks
    Jay SenSharma
    http://jaysensharma.wordpress.com (WebLogic Wonders Are Here)

  • I'm not able to run a simple Hello Program in java

    I have just now installed jdk 1.3.1_2.
    I have set the path and class path.
    I'm able to compile the class without any errors but am not able to run the program.
    when i say java Hello(after compiling Hello.java), i'm seeing the following error:
    Exception in thread "main" java.lang.NoclassDefFoundError:Hello
    Thanks in advance in this regard

    Hmm..
    Okay.. set aside any import or package stuffs.. lets say about a simple HelloWorld program which is called Hello.class. It resides in c:\, which means the full path is c:\Hello.class.
    Make sure you got one of your path as c:\jdk1.3\bin(assuming you are using jdk 1.3).
    If you are in the same directory as Hello.class, which is c:\>, you can execute the class file by typing:
    C:\>java Hello
    If you are not in the same directory and you wishes to run the class file, example you are in directory temp now:
    C:\Temp>java -cp C:\ Hello
    So the cp set will be just c:\. Hope that answers your question somehow.. well... if I never intepret it wrongly.

  • Problem while executing simple java program

    Hi
    while trying to execute a simple java program,i am getting the following exception...
    please help me in this
    java program :import java.util.*;
    import java.util.logging.*;
    public class Jump implements Runnable{
        Hashtable activeQueues = new Hashtable();
        String dbURL, dbuser, dbpasswd, loggerDir;   
        int idleSleep;
        static Logger logger = Logger.getAnonymousLogger();      
        Thread myThread = null;
        JumpQueueManager manager = null;
        private final static String VERSION = "2.92";
          public Jump(String jdbcURL, String user, String pwd, int idleSleep, String logDir) {
            dbURL = jdbcURL;
            dbuser = user;
            dbpasswd = pwd;
            this.idleSleep = idleSleep;
            manager = new JumpQueueManager(dbURL, dbuser, dbpasswd);
            loggerDir = logDir;
            //preparing logger
            prepareLogger();
          private void prepareLogger(){      
            Handler hndl = new pl.com.sony.utils.SimpleLoggerHandler();
            try{
                String logFilePattern = loggerDir + java.io.File.separator + "jumplog%g.log";
                Handler filehndl = new java.util.logging.FileHandler(logFilePattern, JumpConstants.MAX_LOG_SIZE, JumpConstants.MAX_LOG_FILE_NUM);
                filehndl.setEncoding("UTF-8");
                filehndl.setLevel(Level.INFO);
                logger.addHandler(filehndl);
            catch(Exception e){
            logger.setLevel(Level.ALL);
            logger.setUseParentHandlers(false);
            logger.addHandler(hndl);
            logger.setLevel(Level.FINE);
            logger.info("LOGGING FACILITY IS READY !");
          private void processTask(QueueTask task){
            JumpProcessor proc = JumpProcessorGenerator.getProcessor(task);       
            if(proc==null){
                logger.severe("Unknown task type: " + task.getType());           
                return;
            proc.setJumpThread(myThread);
            proc.setLogger(logger);       
            proc.setJumpRef(this);
            task.setProcStart(new java.util.Date());
            setExecution(task, true);       
            new Thread(proc).start();       
         private void processQueue(){       
            //Endles loop for processing tasks from queue       
            QueueTask task = null;
            while(true){
                    try{
                        //null argument means: take first free, no matters which queue
                        do{
                            task = manager.getTask(activeQueues);
                            if(task!=null)
                                processTask(task);               
                        while(task!=null);
                    catch(Exception e){
                        logger.severe(e.getMessage());
                logger.fine("-------->Sleeping for " + idleSleep + " minutes...hzzzzzz (Active queues:"+ activeQueues.size()+")");
                try{
                    if(!myThread.interrupted())
                        myThread.sleep(60*1000*idleSleep);
                catch(InterruptedException e){
                    logger.fine("-------->Wakeing up !!!");
            }//while       
        public void setMyThread(Thread t){
            myThread = t;
        /** This method is only used to start Jump as a separate thread this is
         *usefull to allow jump to access its own thread to sleep wait and synchronize
         *If you just start ProcessQueue from main method it is not possible to
         *use methods like Thread.sleep becouse object is not owner of current thread.
        public void run() {
            processQueue();
        /** This is just another facade to hide database access from another classes*/
        public void updateOraTaskStatus(QueueTask task, boolean success){
            try{         
                manager.updateOraTaskStatus(task, success);
            catch(Exception e){
                logger.severe("Cannot update status of task table for task:" + task.getID() +  "\nReason: " + e.getMessage());       
        /** This is facade to JumpQueueManager method with same name to hide
         *existance of database and SQLExceptions from processor classes
         *Processor class calls this method to execute stored proc and it doesn't
         *take care about any SQL related issues including exceptions
        public void executeStoredProc(String proc) throws Exception{
            try{
                manager.executeStoredProc(proc);
            catch(Exception e){
                //logger.severe("Cannot execute stored procedure:"+ proc + "\nReason: " + e.getMessage());       
                throw e;
         *This method is only to hide QueueManager object from access from JumpProcessors
         *It handles exceptions and datbase connecting/disconnecting and is called from
         *JumpProceesor thread.
        public  void updateTaskStatus(int taskID, int status){       
            try{
                manager.updateTaskStatus(taskID, status);
            catch(Exception e){
                logger.severe("Cannot update status of task: " + taskID + " to " + status + "\nReason: " + e.getMessage());
        public java.sql.Connection getDBConnection(){
            try{
                return manager.getNewConnection();
            catch(Exception e){
                logger.severe("Cannot acquire new database connection: " + e.getMessage());
                return null;
        protected synchronized void setExecution(QueueTask task, boolean active){
            if(active){
                activeQueues.put(new Integer(task.getQueueNum()), JumpConstants.TH_STAT_BUSY);
            else{
                activeQueues.remove(new Integer(task.getQueueNum()));
        public static void main(String[] args){
                 try{
             System.out.println("The length-->"+args.length);
            System.out.println("It's " + new java.util.Date() + " now, have a good time.");
            if(args.length<5){
                System.out.println("More parameters needed:");
                System.out.println("1 - JDBC strign, 2 - DB User, 3 - DB Password, 4 - sleeping time (minutes), 5 - log file dir");
                return;
            Jump jump = new Jump(args[0], args[1], args[2], Integer.parseInt(args[3]), args[4]);
            Thread t1= new Thread(jump);
            jump.setMyThread(t1);      
            t1.start();}
                 catch(Exception e){
                      e.printStackTrace();
    } The exception i am getting is
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe
    Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
    JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820] Please help me.....
    Thanks in advance.....sathya

    I am not willing to wade through the code, but this portion makes me conjecture your using an Oracle connect string instead of a class name.
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe

  • What is the best Videoing Chatting program to use for my Macbook Pro?

    I have had Skype for a while now and recently I updated to Skype 5, and the call qaulity is absolutely miserable, it keeps being blurry and freezing and it's a pain to try and talk through. So I was wondering is there any changes or fixes I can do to possibly make it better or improve the quality of my calls? If not is there any other good video chatting programs with good call qualities for Mac?
    Im using Skype on my macbook pro, just saying.

    How can you check if your wifi is good enough for a quality video call?
    Yes I would post on Skypes forum, but there people their are not very helpful or supportive, so Im trying to get other people's opnions on ways to improve the call quality or find a better program.
    Does anyone use any other video calling program that is just as good if not better? If so could you please mention it. I've looked on Google and I know some of the softwares or programs out there, but Id like to get peoples first hand experience with the programs and what they think of some of them out there.

Maybe you are looking for