Servlet Based Chat program.

Hi,
I would like to develop a web based chat application,
Does anyone of you have any links which are helpful for me to refer?
Do you know whether are there any sample servlet chat program ?
Thank you.
Your help will be appreciated.

I have forgotten to mention that the chat program will be web based using Java Servlet technology.

Similar Messages

  • Internet Packet based Chat

    Hi there,
    Im creating an internet based chat program, with a client, and a server program. It works by sending and recieving packets. I can get both my applications sending packets which are in a char array of maximum size 285. I know I have them sending because I have used hyperterminal and seen the output I want. However, they dont seem to be displaying on the other program. The code I have is this to send:
            public void sendPacket (char[] packet) {
                list.add("sendPacket function recieved: " + new String (packet));
                //send the packet passed to it
                try {
                    for(int i = 0; i < PACKETLENGTH; i++)
                        System.out.print(packet);
    bw.write(packet[i]);
    } catch (IOException e) {
    list.add("Error Sending packet.");
    The code I have to recieve it which doesnt seem to work is this:
            public void run()
                    while (true)
                            try                         //HANDLE RECIEVED MESSAGES
                                list.add(br.readLine());
                            }catch (Exception e){}
         }Could it be because the packets are larger than one line? Im fairly new to programming, and hope someone can help me out with this, because all has been going well with this project until now.. :-(
    the list is the window which displays all the messages, and bw and br are bufferedreader and bufferedwriter,,
    -Tom

    just a follow up question.
    but when you send it through a socket maybe, don't
    they like get transported as a raw data (not java
    specific types). Yes. What led you to believe that a char was "raw" data?
    Or alternatively, what led you to believe that you could read raw data as if it were a String?
    This doesn't work:
    String hello = new char[];And that's essentialy what you tried to do.
    My point is im confused on whether the types would
    really matter. Yes. If you write bytes, you must read bytes. If you write chars you must read chars. If you write String objects, you must read String objects.
    Take a look at ObjectInputStream and ObjectOutputStream.
    Dave.

  • Java based Chat console works fine, but does not automatically scroll down to last chat item

    Hi,
    I am currently facing a problem with a Chat program using jsp (Java Server Pages) where the chat console works perfect except for one little thing.
    The chat window does not automatically scroll down to the last reply in the chat window.
    the code used to scroll down to the last items (based on Netscape) is the following:
    <pre><nowiki>if (navigator.appName.indexOf("Netscape") != -1) {
    isOther = (navigator.appVersion.substring(0,1) == "3");
    isNS4 = (navigator.appVersion.substring(0,1) == "4");
    isNS6 = (navigator.appVersion.substring(0,1) == "5");
    } else if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1) {
    isIE = true;
    } else if (navigator.appName.indexOf("Opera") != -1) {
    isOpera = true;
    } else {
    isOther = true;
    if (navigator.platform.indexOf("Mac") != -1)
    isMac = true;
    if (isOther)
    alert("Sorry but you will have to upgrade your browser to NS4+ or IE4+ for this to work properly.");
    function setScrollProperties() {
    if (isMac) {
    scrollStart = 0;
    scrollEnd = answerFrame.document.height - scrollStart;
    } else {
    scrollStart = 0;
    scrollEnd = answerFrame.document.height - scrollStart;
    function doScroll() {
    documentYposition += scrollAmount;
    window.scrollTo(0,documentYposition);
    if (documentYposition < scrollEnd) {
    setTimeout('doScroll()',slowScrollInterval);
    }else if (moreScrolling){
    moreScrolling = false;
    scrolling = false;
    startScroll();
    }else{
    scrolling = false;
    }</nowiki></pre>
    I cannot see what goes wrong in here and the manufacturer does not know how to fix this either.
    Irritatingly this scrolling function is working normally in IE, Chrome and some other browsers.
    I sure hope you can help me, as this is a very irritating problem that needs to be solved.
    Best regards,
    Corné Snoek

    Hi,
    sorry for such a late reply. I tried modifying the java bean to resize the JScrollPane object also but even that didn't work. Then I hardcoded the size of my Java Bean in my forms code by trial and error. For example, the size of the bean area was 381x169. The values that I had to pass to the "setSize" bean method were 510x195. This made the bean exactly fit the bean area. Seems crazy to me, but there it is.
    Anyway, thank you.
    Manu

  • Integrate A Chat Program with a Web Page

    iIn JSP Based Web Page
    Integrate A Chat Program with a Web Page

    I have an iPad 3rd generation and I get that message as well so it has nothing to do with having an iPad 2. The message means exact,y what it says, there was a problem loading the web site. In some situations, it just might be a problem with the website itself. Please note that I said in "some" situations. If you are getting this message every single time that you try to load a page, something is wrong.
    Did you clear Safari, close all apps and then reset the iPad? Settings>Safari>Clear history and website data.
    Now close all apps. In order to close apps, you have to drag the app up from the multitasking display. Double tap the home button and you will see apps lined up going left to right across the screen. Swipe to get to the app that you want to close and then swipe "up" on the app preview thumbnail to close it.
    Next, reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • Is that possible ?  (Chat Program)

    I just found a great source code for a basic Server/Chat Program, but both works on a Frame... I want the Client to run on an Applet (Web Page) and the server to run on a PC in a Frame.
    Is that possible... ? If yes, how do I do that? I can send the source code if you want.

    Hi,
    I am developing a socket server and client application for some other purpose than chatting. In my application, the <b>Log Server</b> is a Daemon Thread always be listening to the client requests. On listening to a request it spawns a <B>RequestProcessor</B> thread to process the requests.
    The client is a session manager servlet. When the new HTTP request is taken by it, it has to write the status of the HTTP request into to the remote log files on the Log server. So at the beginning HTTP request, it has to write into the remote log file. And then process the request which may take a few seconds. At the HTTP request process, this has to write again into the remote log file on Log Server.
    In my code now: The session manager will open a client socket to the server. At the beginning of the HTTP request, it will getOutputStream() of that socket and flushes the data to the OutputStream. Please note that it doent close that client socket. Then it does some processing. Then at the beginning of the HTTP request, it will re-use the same client socket and get the outputStream of that socket and flushes the data to the OutputStream.
    If I do this, what I observed is unless i close the client socket, the data is not actually being written to the outputstream. The server side <B>RequestProcessor</B> thread is able to read the data from the sockets inputstream, only when the client socket is closed.
    Please suggest me how to resolve this. So that when ever the data is flushed to the outputsteram, the server side <B>RequestProcessor</B> thread must be able to read that immediately.
    Please let me know asap.
    Thanks in advance
    Murali

  • [b]can I use servlets for Chat? new to servlets[/b]

    I want to a chat application for someprof and students
    I am using multicasting technique to send and receive messages
    I used applets and created it but applets don't support java.net's MulticastSocket so I used certificate
    Now I want to use servlets for this in JSP because I called applets from JSP
    Can it be possible? If yes please clearify.

    it is possible
    you could create a jsp page that would update like 10 or 20 or whatever number of ServletContext attributes.
    in the jsp_service or in the doPost or doGet method of a servlet:
    String messageFromUser=request.getParameter("msg");
    int num=15;
    String[] chat=new String[num];
    chat[0]=getServletContext().setAttribute("chatLine" + 0, messageFromUser);
    for(int i=1; i<num; i++) {
        String previousMessage=getServletContext().getAttribute("chatLine" + (i-1));
        chat=getServletContext().setAttribute("chatLine" + i, previousMessage);
    out.println(chat[i]);
    however, there is a pretty decent client/server chat program that can run as an applet here:
    http://planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=4397&lngWId=2

  • 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

  • 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.

  • Is it possible to make an "internet" chat program?

    I have already made a chat program for a LAN, but I want to somehow make it usable over the internet. Is there a way to make the program use your internet ip, instead of your lan ip?

    Hello: I gott a similar trouble over writing an internet chat app. I have an app that works on a local server, works with a local database, i want it to work on internet, but i dont know how to do it, i also use a server app for replying client queries. I'm using sockets and i don't know how a client can works throught a LAN - proxy or router internet acces - to the app if i have to place it on a web server

  • Java Update 5 (1.0) breaks Java for Volano based chats

    I installed the Java Update 5 (1.0) for Leopard on my Intel based Mac mini and then was unable to enter Volano (Java applet) based chat rooms. I was forced to reinstall my system to revert to my prior version of System 10.5.8 in oder to be able to continue use the Java based Volano chats. The update that will NOT work states: "This release updates Java SE 6 to to version 1.6.0_1.5, J2SE 5.0 to version 1.5.0_20, and J2SE 1.4.2 to 1.4.2_22."
    According to Volano developers -
    Note that Apple calls Java 5 (version 1.5) "J2SE 5.0", while it calls Java 6 (version 1.6) "Java SE 6". I think I finally have the following chart correct:
    J2SE 5.0 = Java 5 (version 1.5)
    - Available as 32-bit and 64-bit packages in Leopard
    - Removed in Snow Leopard
    Java SE 6 = Java 6 (version 1.6)
    - Available only as 64-bit packages in Leopard
    - Available as 32-bit & 64-bit packages in Snow Leopard
    In Leopard, the 32-bit Safari can run Java applets only with the 32-bit
    J2SE 5.0 support. To run applets using Java SE 6, you need to bypass
    Safari using the "appletviewer" Terminal command in Leopard, or upgrade
    to Snow Leopard where Safari can run Java SE 6.
    Volano says the possible work arounds for Leopard users (10.5.8( are:
    According to what I've read, if you have a 64-bit capable Intel processor (i.e., an Intel Core 2 Duo), the software update that you removed should have given you 64-bit Java SE 6 even on Mac OS X Leopard (10.5). Java SE 6 works fine with the VOLANO applets, but unfortunately the Safari browser that runs the applets is only 32-bit on Leopard, so applets in Safari still run with the 32-bit Java SE 5 instead of the 64-bit Java SE 6.
    So you have three options to solve the problem -- two free options (one rather easy, one more difficult), and one easy non-free option.
    (1) The Free and Relatively Easy Option
    If you have an Intel Core 2 Duo processor (not a Core Solo or Core Duo), you can install all the software updates from Apple so that you'll have the 64-bit Java SE 6.
    About Java for Mac OS X 10.5 Update 2 http://support.apple.com/kb/HT2733 "Java SE 6 is available on 64-bit, Intel-based Macs only."
    You would then modify your Java Preferences so that Java SE 6 is chosen first for the Java Application Runtime settings. You can verify the modified setting by running the following "java -version" command from the Terminal application (Finder > Applications > Utilities > Terminal):
    $ java -version
    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
    There are some more detailed instructions here:
    Install Java 6 on Mac OS X Leopard
    http://gephi.org/users/install-java-6-mac-os-x-leopard/
    Then you can bypass Safari and run the applet directly in the 64-bit Java SE 6 using the "appletviewer" command in Terminal. For example:
    $ appletviewer http://www.actionchat.com/chat/english.shtml
    You just put the URL of the page containing the VOLANO chat applet you want to load. I just tried it on my system, and it works fine. You bypass Java SE 5, which is broken for the VOLANO applets, and you bypass Safari, which cannot run the 64-bit Java SE 6. Instead, you run the VOLANO applet using your Java SE 6 directly!
    (2) The Free and Not-So-Easy Option
    You can download and install SoyLatte as an alternative to the Apple Java VM for your Mac OS X Leopard system.
    SoyLatte: Java 6 Port for Mac OS X 10.4 and 10.5 (Intel)
    http://landonf.bikemonkey.org/static/soylatte/
    I have not tried SoyLatte on my iMac, though.
    (3) The Best but Non-Free Option
    For only $29, you can upgrade your system to the latest Snow Leopard and get both the 32-bit and 64-bit Java SE 6 along with a Safari Web browser that works with Java SE 6 for running applets!
    Mac OS X 10.6 Snow Leopard
    http://store.apple.com/us/product/MACOS_XSNGL
    I hope this information is of help to any Leopard users having trouble with the latest Java update.

    Thanks for the suggestion.
    Please bear in mind that this issue, presumably introduced by Apple's own update, affects not only the command line java interpreter but any other app that depends on Java (including some GUI apps). So it perhaps fits the larger scope of Leopard instead of the Unix area.
    Message was edited by: bhapca

  • Help me in my chat program please

    hi,
    Im doing chat program same as yahoo messenger using Java.Please help me in creating rooms....so that it will be a great help for me to finish my project..
    Thanks in advance
    PadmaPriya.

    hi,
    Actually i have a common room in which people enter through a login screen and chat...it shows the user list .
    what i want to do is i want to add a combo box in the login screen with mulitple rooms...the user should select rooms and then must be able to chat....in their rooms...
    so that many rooms would function at a time..and people will be chatting correspondingly....can u please help me in doing that...
    Thanks in advance
    PadmaPriya.

  • I am using a code based typesetting program (not WYSISYG) that outputs PDFs. I am producing 100 plus pages that have multiple graphics on each page. I need to know how to format a PDF command that I can incllude in my programming that will tag my graphics

    I am using a code based typesetting program (not WYSISYG) that outputs PDFs. I am producing 100 plus pages that have multiple graphics on each page. I need to know how to format a PDF command that I can incllude in my programming that will tag my graphics with "Alternative Text".
    I know that with a Microsoft product graphics can be tagged before a PDF is made. I need to know how to do this with my programming.

    The Acrobat SDK might be a starting point.
    From there, perhaps a plug-in (built with C+).
    Perhaps with a licensed release of a PDF Library (this could be $$).
    The viable and cost effective alternative is use the tried and true.
    Authoring in an appropriate authoring application with appropriate tag management.
    Example:  Adobe InDesign; Adobe FrameMaker or MS Word with PDFMaker (comes with install of Acrobat).
    This way you place "Alternative Text" when mastering content in the authoring file.
    Going the route and with some look-see (research) you may find programmatic approaches to placing the alt txt in the authoring file.
    Note: as discussed in the Matterhorn Protocols there is no programmatic method that provides a fully accessible PDF (specifically, that is an ISO 14289-1, PDF/UA-1 compliant PDF).
    Regardless, here you have a sub-forum for discussions on Acrobat usage.
    Consequently discussions on/of 3rd party software is rather out of scope eh.
    Be well...

  • Disconnected from ANY chat program when I go into sleep mode

    I am using an airport express connection with road runner. When my computer goes into sleep mode, any chat program I am using is disconnected -- this happens with AIM, iChat, and Netscape Navigator's chat screen. As soon as I move my mouse, or touch the keyboard, and go active, AIM automatically reconnects. Any ideas on how I can remain signed into a chat service when I go into sleep mode?

    In sleep mode your mac only keeps the data in the RAM. all other things will be turned off, so that it´s impossible to stay online with the chat applications.

  • Web based mail program like hotmail or yahoo

    Hi All,
    How do I create a web based mail program like yahoo or hotmail using Java Mail API?
    If any one knows please let me know.
    my email id: [email protected]
    Thanks and Regards,
    Sarat

    Dear sarat,
    First of all u tell me why u want to develop web based mail like yahoo or hotmail, If u want to develop for learning purpose then start from today using java mail API. So u should know Java Mail API. and some webbase scripting like JSP and HTML.
    Once u start and if any problem then write in forum we will solve.
    If u don't want to develop for learning purpose then u buy it.
    Regards
    Kinjal Shah.

  • Creating Emoticons in a chat program

    Hi all, I wish to write a chat program which has got emoticons?What is the best way to implement emoticons in a chat program? Thank you in advance...:)...

    A subtle hint for the future topics: do not use the browser back button to edit the message. Rather use the edit button which you can find at the top right of your posted message (this edit button is available as long no one has replied on your message).

Maybe you are looking for

  • Get the Values with null for all dates

    hi,  i have a scanrio to get the sales trend. The data look like below CREATE TABLE #T1 ( Item varchar(50), SalesDate Date, Quantity int INSERT INTO #T1 VALUES ('Item1', '2013/02/01', 3) INSERT INTO #T1 VALUES ('Item2', '2013/02/01', 5) INSERT INTO #

  • Movies media playing error from Pen drive to tv

    hi all, i am facing some weir problem here, during my pen drive playing movies on tv, its show a lot of cracked icons as attached photos. and the cracked icon will stop my movies continued to play smoothly...actually i save 18 movies clips only but e

  • Just completed a podcast via a Skype call. Mixed it in GarageBand, and not sure how to send it via email.

    Would love to know how to save the podcast into a manageable audio file and share it with the site administrator of my new website.  Is it easier to upload it to Itunes and then direct the admin. to the podcast to download? Any help will be greatly a

  • Socket seems too slow...maybe java.nio?

    Hello In our system I have to receive Multicast Packets repeats very quick(1-5 ms). I have to link them one after an other in the order they sent. And if I miss a packet, something will go wrong... I have to listen to different IPs and I use differen

  • Execute Query in different Window

    I want to execute query on block which is placed in different windows. I create two different windows A1 and B1 I want to execute Query on B1 while my cursor is on A1 and based on A1.item1.