Voice Chat and MailClient in Java

I am developing Chat application with VOICE CHAT
and MAILBOX as additional features
can anyone send me the source code of Voice chat
application and steps to develop a mailbox

This will be useful for voice chat developing:
http://forum.java.sun.com/thread.jspa?threadID=232769&tstart=75

Similar Messages

  • Voice chat using java rtp

    hi
    i got voice transmission and receiving in java rtp but some what delay is there
    i tried reduce the delay but still i have problem
    i tried with GSM_RTP,LINEAR,ULAW ,etc but still delay is there
    any one help me please
    source code is avaliable in :
    http://javasolution.blogspot.com/2007/04/simple-application-for-voice.html

    bendash wrote:
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?If you need to do the voice chat in Java for whatever reason, then yes...
    - Is it possible to somehow fix that delay? if yes, then how?From what I saw from glancing at that code, it's transporting the audio streams via a TCP stream. TCP streams retransmit data when it's lost, which is actually something that you don't want in a real-time application. If you lose some packets with audio data, and those are retransmitted, your receiver is getting progressively more and more behind (because the audio stream has to wait for the missing bytes to arrive before it can continue.
    For a simple application like yours, your best bet would be to divide the audio stream into buffer-sized chunks (1024 bytes might be a good buffer size), and transmit those in UDP packets. Make sure to add a packet number to the UDP packets. On the other end, just write some code so that out of order packets are ignored (so if packet 4 arrives after packet 6, for instance, you drop that packet rather than playing it after 6... so you'd get 123(silence)567...

  • Voice chat using Sound API?

    Hi there,
    I'm a university student, trying to find a way to create an application in java with voice chat feature. It will actually be a call center simulator app consisting of two parts, a server and a client part:
    The multithreaded server manages the clients, and the JPA database;
    The client's job is to login to the server, and then he'll get a randomly selected person's data and phone number by the server - in this case, IP address is the phone number, and the person is another available client. Then he can call that person, ask the questions regarding for example, a bank card (if it is a bank's call center), jot down the answers to a form, and then hang up; then the client will send said person's data to the server, who updates it in the database.
    For the voice chat part, I want to use the Java Sound API, and I've found this example:
    [Voice Chat Using Java|http://javasolution.blogspot.com/2007/04/voice-chat-using-java.html]
    But although this example works, there's a delay of 1.5 - 2 seconds in the audio.
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?
    - Is it possible to somehow fix that delay? if yes, then how?
    Also, how would you imagine/structure a program like that?
    Let me remind you that it's only a simulation, and we're not talking about actual phone-to-net calls or something like that; only LAN and internet calls, so clients should need no more than a microphone and a speaker to work with it, and also, the server shouldn't need extra hardware,too.
    Thank you in advance for your replies,
    Ben Dash
    university student

    bendash wrote:
    My questions are:
    - Is it a good idea to implement a voice chat feature using the Java Sound API, something similar to the example above on the link?If you need to do the voice chat in Java for whatever reason, then yes...
    - Is it possible to somehow fix that delay? if yes, then how?From what I saw from glancing at that code, it's transporting the audio streams via a TCP stream. TCP streams retransmit data when it's lost, which is actually something that you don't want in a real-time application. If you lose some packets with audio data, and those are retransmitted, your receiver is getting progressively more and more behind (because the audio stream has to wait for the missing bytes to arrive before it can continue.
    For a simple application like yours, your best bet would be to divide the audio stream into buffer-sized chunks (1024 bytes might be a good buffer size), and transmit those in UDP packets. Make sure to add a packet number to the UDP packets. On the other end, just write some code so that out of order packets are ignored (so if packet 4 arrives after packet 6, for instance, you drop that packet rather than playing it after 6... so you'd get 123(silence)567...

  • Voice Chat

    I have a Torch 9810 and I am having a problem with Voice Chat. I have never used it, but somehow two of my BBM contacts are showing the green icon on the top right corner when I am BBM'ing them. How do I remove voice chat from those contacts. I am being charged by my provider for something I am not using.
    Solved!
    Go to Solution.

    Because the other BB user must have the most recent version of BBM installed that includes voice chat AND they have to be on wifi, or, on some devices and carriers, 4G.
    1. Please thank those who help you by clicking the "Like" button at the bottom of the post that helped you.
    2. If your issue has been solved, please resolve it by marking the post "Solution?" which solved it for you!

  • Video & Voice Chat Not Working With ichat

    Voice Chat and Video Chat is not working with ichat 6 in booth google and yahoo. One side is ichat and the other side is yahoo & google talk clients, Please confirm whether its a workable scenario or it only supports ichat to ichat.
    Thanks & Regards
    Sreejith R

    Hi
    Other alternatives based on the amount of info in your post.
    Has she set up her Google Name in iChat or is she logged on via the Web Site (Google Mail page) ?
    iChat cannot Video to the Google Mail Login page chat option or to the app called GoogleTalk on a PC.
    Another thing.
    If you login to the GoogleMail Web pages you will get logged out of iChat (GoogleTalk account) to a partial extent which may explain the loss of Video or Audio iCons.
    iChat reports in a Text chat window that you have Logged Off.
    However you seem to be able to continue the chat - but it separate from the web Page chat - You send from the web page and that chat will get the next response, send from iChat and it gets the next response (I can't remember if the Buddy told me he got two Chat windows at his end)
    9:26 PM Wednesday; May 12, 2010
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"

  • How can i run java on the i mac to start the voice chat?

    i have imac
    and i have downloaded java
    i want to open voice chat websites
    e.g. www.63oon.com

    Hello,
    Not sure, but could it be this?
    Java for OS X 2012-006: How to re-enable the Apple-provided Java SE 6 applet plug-in and Web Start functionality
    http://support.apple.com/kb/HT5559

  • Sound, voice chat, yahoo messenger and VPC 6

    Okay perhaps off topic..perhaps not......how do I get sound to work in Yahoo messenger v 7 w/ voice chat via VPC 6 on an AL 15 Powerbook???
    And does the AL 15 have a built in Microphone??

    Does the microphone work while running VPC?
    I don't know, but I think you can easily check. While you're running VPC, go into System Preferences > Sound > Input. (You can access System Preferences from the Apple menu in the upper left-hand corner of your screen. I'm assuming that you can do this while running VPC. If I'm wrong on this, please stop reading this worthless post. ;-))
    Look at the meter that reads "input level," just above the slider that reads "input volume." If there's any significant ambient noise where you are, or if you speak at a decent volume out loud (it doesn't even have to be near the mic, which is located beneath the left speak grille), you should see the "input level" fluctuate if the mic's working properly. (The default setting for the "input volume" is midway on the slider. If it's all the way to the left, the mic will not pick up any sounds.)

  • Chat and email applications programmed in java

    Can someone tell me where I can find some applications about chat and email with codes and
    tutorial?
    I have to work about these topics with some students of mine.
    Thanks
    Eugenia Mariani

    i'm new to java.so i don't know how much advance thing you need.bue this helped me.
    go to
    http://java.sun.com/developer/onlineTraining/JavaMail/
    it give basics

  • Voice chat problem on gmail,skyp​e and oovoo yahoo messanger works at time

    Voice chat problem on gmail,skype and oovoo yahoo messanger works at times.
    Pavilion dv6, i7, windows 7
    at times it tells that your microphone is really quet.
    Thanks,
    Ranjith

    Sounds like the network's firewall or other security feature is blocking the ports used for sending the emails.
    What type of neworks do not work? A businees network?

  • Poor video and voice chat

    hi im new here first time, i have a problem with skype and yahoo! when i use the cam and or voice chat in either of them the cam is very poor and voice chat fails , some days the  the whole pc system grinds too a halt wont change page or log off. ive checked the speed and upload speed and it says its ok for good video andvoce chat?,,, download is 23ish and upload is 5ish my ip limit is 24 and 10. anyone have any ideas ive line checked and its quiet and everytime i have a problem ive checked speed .says its ok. many thanks in advance. o bt w its been like this since it was installed 1-2 months ago .

    Hi
    Have you checked Skype with another pc or Iphone etc?
    With those speeds, skype should be fine.
    i therefore wonder if the pc is the stumbling block?
    John

  • WRT54GS V.1 and SOE Games , Voice Chat

    After a few weeks of trying every method of troubleshooting.. the voice chat feature from SOE games still does not work when connected through my router.  If I connect dsl modem directly to pc, the voice feature works.
    This was their last recommendation, which btw I have updated firmware to the latest version already:
    "Hello again,
    From the results you've just shared it looks like your router is unable to send/receive VoIP data, because the packets are too large. In order to fix this, you will need to update your router's firmware, hopefully Linksys has a new firmware with a VoIP data fix to allow the router to process the larger data packets."
    How can I verify the packet size being too large?  Is this true?

    Have you ever used the voice chat feature from SOE games when connected through the router ?
    I doubt it...It seems there is no such firmware with a VOIP data fix...
    Remember, after a firmware upgrade, you must reset the router to factory defaults, then setup the router again from scratch.  If you have not done this since your last firmware upgrade, please do this now and see if it corrects your problem...
    To reset the router press and hold the reset button for 30 seconds...Release the reset button...Unplug the power cable from your router, wait for 30 seconds and re-connect the power cable...Now re-configure your router...

  • Client for Second Life and/or Voice chat ?

    Is there a client for Second Life and/or Voice chat ?

    Yes, the app is called Pocket Metaverse. There is a free version and a Pro Version that costs $2.99.

  • 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

  • Voice chat not working.

    Hello,
    I was just trying the code given in JMF documentation for voice chat. When i ran the below given code, it doesn't throw any error but after running this program when i speak anything into my microphone i am unable to hear anything. What can be the problem?
    package sendmicrophonedata;
    import java.io.IOException;
    import java.util.Vector;
    import javax.media.CaptureDeviceInfo;
    import javax.media.CaptureDeviceManager;
    import javax.media.DataSink;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.NoProcessorException;
    import javax.media.NotRealizedError;
    import javax.media.Processor;
    import javax.media.control.FormatControl;
    import javax.media.control.TrackControl;
    import javax.media.format.AudioFormat;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.DataSource;
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
           // First find a capture device that will capture linear audio
            // data at 8bit 8Khz
            AudioFormat format= new AudioFormat(AudioFormat.LINEAR,
                                                8000,
                                                8,
                                                1);
            Vector devices= CaptureDeviceManager.getDeviceList( format);
            CaptureDeviceInfo di= null;
            if (devices.size() > 0) {
                 di = (CaptureDeviceInfo) devices.elementAt( 0);
            else {
                // exit if we could not find the relevant capturedevice.
                System.exit(-1);
            // Create a processor for this capturedevice & exit if we
            // cannot create it
            Processor processor = null;
            try {
                 processor = Manager.createProcessor(di.getLocator());
            } catch (IOException e) {
                System.exit(-1);
            } catch (NoProcessorException e) {
                System.exit(-1);
           // configure the processor
           processor.configure();
           // block until it has been configured
           processor.setContentDescriptor(
               new ContentDescriptor( ContentDescriptor.RAW));
           TrackControl track[] = processor.getTrackControls();
           boolean encodingOk = false;
           // Go through the tracks and try to program one of them to
           // output gsm data.
            for (int i = 0; i < track.length; i++) {
                if (!encodingOk && track[i] instanceof FormatControl) {
                if (((FormatControl)track).
    setFormat( new AudioFormat(AudioFormat.GSM_RTP,
    8000,
    8,
    1)) == null) {
    track[i].setEnabled(false);
    else {
    encodingOk = true;
    } else {
    // we could not set this track to gsm, so disable it
    track[i].setEnabled(false);
    // At this point, we have determined where we can send out
    // gsm data or not.
    // realize the processor
    if (encodingOk) {
    processor.realize();
    // block until realized.
    // get the output datasource of the processor and exit
    // if we fail
    DataSource ds = null;
    try {
    ds = processor.getDataOutput();
    } catch (NotRealizedError e) {
    System.exit(-1);
    // hand this datasource to manager for creating an RTP
    // datasink our RTP datasimnk will multicast the audio
    try {
    String url= "rtp://192.168.1.255:8888/audio";
    MediaLocator m = new MediaLocator(url);
    DataSink d = Manager.createDataSink(ds, m);
    d.open();
    d.start();
    } catch (Exception e) {
    System.exit(-1);

    LaalaPanchal wrote:
    Hello,
    I was just trying the code given in JMF documentation for voice chat. When i ran the below given code, it doesn't throw any error but after running this program when i speak anything into my microphone i am unable to hear anything. What can be the problem?Why exactly are you expecting to hear anything? You don't have anything in your code to render sound, so why're you expecting it to?

  • Problem in voice chat applet

    hi all,
    I am developing a Voice chat applet using java(JDK1.4,JMF). If i run my programs of transmitting voice and receiving voice from one machine to another machine(Without applet), its working fine.
    When i am sending voice from my server machine, and receiving on someother machine by application, its working fine.
    But if i am using my applet from some other machine(Other then server) its creating problems. Its showing some errors.
    Can you suggest some solutions??
    Thanks in advance.
    Abhishek

    hi,
    i also develop the voice chat application. can you send your source code to me. may be i can help you to solve your problems.
    my email is [email protected]

Maybe you are looking for

  • Please, help me, What is the difference between SCWCD and SCBCD ?

    {color:#000000}*HI, Everyone* I want to know major difference between Sun Certified Business Component Developer and Sun Certified Web Component Developer. Who should go for business component developer and who should go for web component developer?

  • MTO consumption based planning how it works

    Hi,   I am using VB mrp type  for some bom components with reorder points .when i run an MRP for header material with respect to a sales order/ line item it is planning for the materials with VB with out considering the reorder point with in my BOM c

  • Word in MAC OS X

    Hello, I would like to ask you some advice. This morning I couldn't open through Word my documents anymore, I can still do that through 'finder'. In word I can still type a document, sent it, save it, mail it, print it, ... but the function: document

  • The SSL certificate of the server is expired

    Today, I accessed Beehive Online via Oracle Beehive Extentions for Explorer. I cannot use Beehive Online with error message "The SSL certificate of the server is expired". How should I do?

  • Problem with opening Archivelink document because of wrong MIME type

    In transaction OAD2 we have a document type FAX which is currently connected to MIME-type application/pdf. This works fine for opening documents having document class FAX and are actuallty a PDF. However, in the past this document type FAX has also b