"BindException: Address already in use" error all the time!

I made a simple program that streams lines of text across the network/internet and a simple client program to display that text. The problem is, regardless of what port I choose, I always get this exception on the server's side:
C:\Users\Nathan\Desktop>java LyricalUploader
Started Listening
Bound
Started Listening
Starting.java.net.BindException: Address already in use: JVM_Bind
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
        at java.net.ServerSocket.bind(ServerSocket.java:319)
        at java.net.ServerSocket.<init>(ServerSocket.java:185)
        at java.net.ServerSocket.<init>(ServerSocket.java:97)
        at LyricalUploader.main(LyricalUploader.java:11)What bothers me is it creates the ServerSocket just fine (that's what the output saying "Bound" means) and if I replace the new LyricalThread(ss.accept()).start(); line in the code below with new LyricalThread(ss.accept()).run();, it works fine, It just can't handle more than one client. I have tried many many ports and they all have the same result. What am I doing wrong?
Here is the code:
import java.net.*;
import java.io.*;
import javax.swing.JFileChooser;
public class LyricalUploader{
public static void main(String args[]){
  ServerSocket ss = null;
  int c=0;
  try{
    while(true){
      System.out.println("Started Listening");
      ss = new ServerSocket(49625);
      System.out.println("Bound");
      new LyricalThread(ss.accept()).start();
  catch(Exception e){
    e.printStackTrace();
    System.exit(1);
import java.net.*;
import java.io.*;
public class LyricalThread extends Thread{
  Socket s = null;
  public LyricalThread(Socket so){
    s=so;
  public void run(){
    try{
      System.out.print("Starting.");
      PrintWriter out = new PrintWriter(s.getOutputStream());
      BufferedReader fin =new BufferedReader(new FileReader("Lyrics.txt"));
      System.out.print(".");
      String line = fin.readLine();
      System.out.println(".Done!");
      while(true){
        while(line!=null){
          out.println(line);
          //System.out.println(line);
          line=fin.readLine();
          Thread.sleep(1600);
        fin.close();
        System.out.println("End of Lyrics.txt file.");
        fin =new BufferedReader(new FileReader("Lyrics.txt"));
    catch(Exception e){
      e.printStackTrace();
      return;
  public static void main(String arg[]){
    new LyricalThread(null).start();
}And the Client code:
import java.net.*;
import java.io.*;
import javax.swing.JFileChooser;
public class LyricalReader{
  public static void main(String args[]) throws Exception{
    Socket s = null;
    BufferedReader sin = null;
    FileOutputStream out = null;
    try{
      System.out.println("Started");
      System.out.print("Connecting...");
      s = new Socket("2.9.19.94",49625);
      System.out.println("Done!");
      System.out.print("Finding song...");
      sin = new BufferedReader(new InputStreamReader(s.getInputStream()));
      String line = sin.readLine();
      System.out.println("Done!\nStarted reading:\n\n\n\n\n\n");
      while(true){
        System.out.println(line);
        line = sin.readLine();
    }catch(Exception e){
      e.printStackTrace();
      sin.close();
      s.close();
      out.close();
    System.exit(0);
}

Hi,
your Server must create only one ServerSocket, not multiples! So write
  try{
    ss = new ServerSocket(49625);
    System.out.println("Bound");
    while(true){
      System.out.println("Started Listening");
      new LyricalThread(ss.accept()).start();
  catch(Exception e){
    e.printStackTrace();
    System.exit(1);
  }and take the creation of the ServerSocket outside the while-loop.
Martin

Similar Messages

  • Web Service Client, BindException, Address already in use, saaj.SOAPExcepti

    Hello,
    Am caught up with an error and i can't get past it, need some help here.
    My application is a batch processing web service client, reads some input rows, sends web service requets, processes the responses and logs it.
    The application runs well in normal mode, but under load(more thread count), I get this wierd error and I can't make it go away.
    java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
    Caused by: java.net.BindException: Address already in use: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    I have properly closed the connections after each web service calls, but it still says Address in use. Please refer below for the complete stack trace and a piece of the code. Am using SAAJ and JWSDP and am not using AXIS api. I have searched the web but couldn't find any solutions.
    This is not an error that server is not closing connections properly as I was able to test with SOAPUI and LoadRunner with even higher threads and it ran without problems. SOAPUI and LoadRunner scripts were executed from the same client machine as my application uses. Please help.
    For each inputrow
    SOAPConnection connection = null;
    try
    SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
    connection = soapConnFactory.createConnection();
    SOAPMessage request = getRequest(inputRow);
    SOAPMessage response = connection.call(request, "http://<<server>>:<<port no>>/Domain/Services/Mgmt");
    finally
    if (connection != null)
    connection.close();                         
    }catch(SOAPException se){
    System.out.println("Error while closing connection. " + se.getMessage());
    connection = null;
    } // End of for loop
    Stack Trace:
    java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptio
    nImpl: Message send failed
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOA
    PConnection.java:121)
    at ClientImpl.getResponse(ClientImpl.java:440)
    at input.InputSampler$MyCallable.call(Sampler.java:63)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOA
    PConnection.java:325)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedP
    ost.run(HttpSOAPConnection.java:150)
    ... 12 more
    Caused by: java.net.BindException: Address already in use: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(Unknown Source)
    at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
    at java.net.PlainSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at sun.net.NetworkClient.doConnect(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.openServer(Unknown Source)
    at sun.net.www.http.HttpClient.<init>(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.http.HttpClient.New(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown
    Source)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Sour
    ce)
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown S
    ource)
    at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOA
    PConnection.java:282)
    Is there something like connection pooling for web services, is that the answer to this issue, if yes, please let me know where i should start.
    Thanks
    Dev

    Move server socket creation out of while loop. You don't need to create new server socket every time.

  • I am using Windows 7 Home Premium 64-bit OS.  I've never had this problem before... today I opened iTunes and it prompted me to download the newest version.  I use iTunes all the time and have updated it multiple times with no issues.  During the installa

    I am using Windows 7 Home Premium 64-bit OS.I've never had this problem before... today I opened iTunes and it prompted me to download the newest version.  I use iTunes all the time and have updated it multiple times with no issues.  During the installation process it gave me an error message that said: 
    Runtime error! 
    Program C:\Program Files\iTunes.exe
    R0634
    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.
    I quit the installation, uninstalled iTunes and rebooted my computer.  I now receive a similar message with a slight difference:
    Runtime error! 
    Program C:\Program Files (x86)...
    R0634
    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.
    I did not leave anything out from the error message.  It doesn't point to a specific file, it just ends with "(x86)..."  Every time I boot up my computer, this error message pops up on my desktop.
    How do I repair this issue?  I have found multiple suggested solutions but am unsure which one is the best, and I don't want to try a bunch of different things for fear I may make the problem worse.  I would like to try and fix this myself if possible but I need to know if that is really possible or if I need to take my computer to someone for repairs.  Any suggestions will be greatly appreciated!!

    Hi lustyln,
    I'm having a little trouble understanding all of what you are trying to explain. From what I can tell, it sounds like your PC has a lot of software problems and you want to know what is supposed to be there and what isn't.
    For reference, here are your product specifications:
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c01893242&lc=en&product=4043282
    To get your PC software back to how it was when it was first purchased, run a system recovery:
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c01867418&lc=en&product=4043282
    I hope this helps.
    ...an HP employee just trying to help where I can, but not speaking on behalf of HP.

  • Enhance/Color Adjust/Color variation, seems to be missing in PSE 12. Can I install another version of PSE to Macbook pro Maverick 10.9.3 that has that feature? I use it ALL the time...

    Enhance/Color Adjust/Color variation, seems to be missing in PSE 12. Can I add/install another version of PSE to Macbook pro Maverick 10.9.3 that has that feature? I use it ALL the time... Thanks.

    Enhance/Color Adjust/Color variation, seems to be missing in PSE 12. Can I add/install another version of PSE to Macbook pro Maverick 10.9.3 that has that feature? I use it ALL the time... Thanks.

  • Where can i find the magnetic lasso tool in adobe photoshop touch? i used it all the time before but suddenly cant find it please help

    i started my photoshop touch after some while and now i cant find the magnetic lasso tool it used to be there i used it all the time for editting but now i cant find it maybe i disabled it somehow. can anyone tell how to enable it again?

    I honestly don't remember a magnetic lasso tool. (I've been using PS Touch since version 1.0.) The closest things I can think of are the Quick Selection Tool, the Scribble Selection Tool and the Magic Wand Tool, all located under the same set of tools (3rd set from the top in the tool panel).

  • IPhone 5 using data all the time

    My husband has had his iPhone 5 for a couple of weeks.  We have Verizon 300 mb plan, as he is mainly just using it for calls and text.  But it is using data all the time!  Today our online Verizon account is showing 59 episodes of data usage.  They are small, but still, why are they there?  All he has done is call and text.  He would like to keep the cellular data on because he texts by talking to it.  He did not send anything close to 59 texts.n was not on the Internet.
    We have turned off practically everything.  Location services, stocks, weather, email, notifications for everything except text and calls.  Stopped it from sending data to Apple.  He has added only 4 apps- cam wow, talking bird, talking cat, and free cell solitaire.  Not signed in for iCloud or Facebook or anything.

    Is Digi a CDMA carrier? or is it GSM/UTMS?
    If CDMA, that's normal. The technology was not designed for data and calling.
    If its GSM, give them a call to seek resolution.

  • When I take a picture with my iPhone 5s and afterward turn it laterally, the picture will not turn. It used to all the time. How do I fix this?

    When I take a picture with my iPhone 5s and afterward turn it laterally, the picture will not turn. It used to all the time. How do I fix this?

    Hi there dworthen,
    It sounds like you are experiencing issues when trying to rotate your display. I would recommend taking a look at the troubleshooting steps found in the article below.
    iOS: Screen does not rotate
    http://support.apple.com/kb/TS3805
    -Griff W.

  • Won't display my gadgets - explorer does - so not gadgets - what gives - use to all the time - not anymore - how do I get them back

    All of a sudden my gadgets don't display in my igoogle home page. Use to all the time and they will if I use internet explorer it just happens with mozilla firefox.
    How do I get them to display properly they just are listed on the left hand side of the screen.

    Symantec need to update their Firefox add-ons so that they are compatible with Firefox 4. They have indicated that for Norton 360 they plan to release an update to Norton 360 to support Firefox 4 in early May - http://us.norton.com/support/kb/web_view.jsp?wv_type=public_web&docurl=20100720113635EN&ln=en_US
    Pending the update by Symantec, if you want to use the Norton add-ons you will need to downgrade to Firefox 3.6.
    To downgrade to Firefox 3.6 first uninstall Firefox 4, but do not select the option to "Remove my Firefox personal data". If you select that option it will delete your bookmarks, passwords and other user data.
    You can then install the latest version of Firefox 3.6 available from http://www.mozilla.com/en-US/firefox/all-older.html - it will automatically use your current bookmarks, passwords etc.
    To avoid possible problems with downgrading, I recommend going to your profile folder and deleting the following files if they exist - extensions.cache, extensions.rdf, extensions.ini, extensions.sqlite and localstore.rdf. Deleting these files will force Firefox to rebuild the list of installed extensions, checking their compatibility, and reset toolbar customizations.
    For details of how to find your profile folder see https://support.mozilla.com/kb/Profiles

  • I just uploaded the updates and now my fast dial is gone and I cannot install it. I use this all the time and I am really upset that it is gone. How do I go back to the previous firefox so ?

    I just updated Firefox and now fast dial doesn't work. I want the old version of Firefox back and my fast dial and I use it all the time.

    iTunes Store- Transferring purchases from iOS device or iPod to a computer
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    How to dowload purchased music

  • What has happened to the iPad 2 finger select and drag technique? Since upgrading to iOS7 it does not work? I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What has happened to the iPad 2 finger select and drag technique?
    Since upgrading to iOS7 it does not work?
    I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What would you like us to tell you? If it doesn't work, there is nothing that we users can do about it.
    Please submit your feature request to Apple at this link: http://www.apple.com/feedback

  • Just upgraded...why can't I see the information section on the left hand side anymore in iphoto '11? I used it all the time.

    I've just upgraded from iphoto '08 to iphoto '11 and I'm really missing the information pane on the bottom left hand side (under where events, album, libraries etc are).  I used to use this all the time when importing photos to sort them into Events and now I can't seem to get it back.  Does it not exist in the new iphoto?  Thanks, Hellen

    That info section is a drawer on the right hand side of the iPhoto window.  Click on the Info button at the lower right corner:
    Click to view full size
    OT

  • I deleted the font section but everything in Photoshop CS5 works.  How can I fixed this because I use fonts all the time? I don't want to purchase another one since this cost me $699:(

    I purchased PhotoshopCS5 Sept 2010 and still use the same MAC. I invertly deleted the font section but everything else works.  How can I fixed this because I use fonts all the time? I don't want to purchase another one since this cost me $699:(

    Which version of mac os x are you using?
    Could you clarify what you mean by "I invertly deleted the font section"

  • I get this error all the time. Only happened since last month. Script: chrome://browser/content/tabbrowser.xml:537

    ever since up upgraded to firefox 6 i have had problems. i get this error all the time Script: chrome://browser/content/tabbrowser.xml:537
    MAKE IT STOP!!!

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode
    *https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • We use Thunderbird all the time and love it, but for about a week it constantly goes into not responding mode. My boss uses the same service at home with no pr

    Thunderbird is a great asset to my boss and I. We use Thunderbird all the time and love it, but for about a week it constantly goes into "not responding mode". My boss uses the same service at home with no problem at all.
    I did an "safe mode" and restart and for a few minutes I thought it was "healed". However, I did a search and the same thing started happening again. The little blue ring starts spinning and "not responding" pops up above the toolbar. Sometime the screen fades to a sort of greyish and no mouse click are responded to, even to close Thunderbird.
    Please help however you can. Our office number is 512.246.3995.
    Thank you,
    Mary

    We wonder if it is a firewall problem that developed here at the office. My boss uses her account at home and all is well, but here, experiences the same issues I described

  • The last week, Firefox will not load up the NEW YORK TIMES. So, I have had to use Safari to do so. If this continues, I'm going to quit using your browser, and begin using Safari all the time!

    The last week, Firefox will not load up the NEW YORK TIMES. So, I have had to use Safari to do so. If this continues, I'm going to quit using your browser, and begin using Safari all the time!

    There are several other similar posts in this forum with the answers. Your post appears third in my Google search today looking for a solution so I thought I'd add the solution here as well.
    It is obviously a bug in either (or both) Firefox and the NYT.
    The quickest solution is to simply go to the VIEW Menu in Firefox, then the ZOOM option and choose RESET.
    I use Mac and this happens in Firefox 3.6.10. It does not happen in other browsers like Safari, Chrome and Camino, and it did not occur before last week.
    It has also occurred in the iOS version of Safari on iPad. Not sure how to fix it there.

Maybe you are looking for

  • Where to see CPU and RAM usage in IPAD 1

    Hi:-) While i have Apps running , I would like to be able to see CPU and RAM in use..and ideas how/where? Thanks

  • Older iMac in need of help

    I have a 5 year old intel iMac using 10.7.4. I feel like it is on its last legs because I get many pinwheels with any click of mouse, and gray screens (when I reboot). I'd like to wait until Sept. for the new models. Any ideas for help in the meantim

  • CKMLCP-Revaluate consumption-----urgent

    Dear all, I performed revaluate consumption for certain material, however,system did not give me any error/warning or information message, this material's status still keep in 'single-level settlement',  would anyone tell me what is the possible prob

  • Slideshows aren't working!!!

    Hello, I have recently had issues with Clam Shell mode with an external monitor and have re-installed my OS X software as a fresh install (as advised by Apple) however as a consequence, my iPhoto 09 reinstall doesn't allow me to create slideshows and

  • Oracle 10g enterprise versus standard

    Hi There! Please a question: I need to explain a customer why it's better to install the oracle 10g enterprise edition than the standard. I founded on metalink Doc ID: Note:271886.1: the different features BUT I founded that both includes the Oracle