Socket not used and just hangs program?

Hi, I'm writing a server class and in it, I try to open a socketserver and a socket. However, I found that when the socket tries to open up, the program will just hang there. I think part of the problem is because eclipse is saying that my socket object is never used. Despite having this line: "socket = serverSocket.accept();" being executed. Can someone shed some light into what is causing this to not be used/hang?
package Server;
import java.io.IOException;
import java.net.*;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Server extends JFrame {
     private JTextArea console;
     private static ServerSocket serverSocket;
     private static Socket socket;
     public Server() {
          super("Server");
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          console = new JTextArea();
          //opens the serverSocket
          try {
               serverSocket = new ServerSocket(5000);
               System.out.println("serverSocket opened");
          } catch (IOException e) {
               e.printStackTrace();
          //opens the socket
          try {
               socket = serverSocket.accept();
               System.out.println("socket opened and didn't hang");
          } catch (IOException e) {
               e.printStackTrace();
          console.setText("Awaiting connection...");
          //finalize
          this.add(console);
          this.setSize(400, 300);
          this.setVisible(true);
     private static void closeAll()
          //closes the socket
//          try {
//               socket.close();
//               System.out.println("socket closed");
//          } catch (IOException e) {
//               e.printStackTrace();
          //closes the serverSocket
          try {
               serverSocket.close();
               System.out.println("serverSocket closed");
          } catch (IOException e) {
               e.printStackTrace();
     public static void main( String args[]) {
          Server serverWindow = new Server();
          closeAll();
          System.out.println("end");
}

Hi, I'm writing a server class and in it, I try to open a socketserver and a socket.Why the socket?
However, I found that when the socket tries to open up, the program will just hang there.And it will do that until someone connects to your server.
I think part of the problem is because eclipse is saying that my socket object is never used.Is it really? I find that rather hard to believe.
The problem is that your socket is never used, by a client. So accept() blocks forever. What exactly did you expect?
The norm is to accept sockets in a loop in a separate thread. And process each accepted socket in another thread, per accepted socket. And to never do blocking I/O in the AWT event-dispatching thread. And not to have servers with GUIs as a matter of fact. And certainly never to have a single static socket variable BTW: this is evidence of very unclear thinking> Even the server socket should be an instance variable.

Similar Messages

  • Why do I keep losing my GarageBand music that is saved on my icloud account one at a time? I have 4 gigs not used and just lost another.

    I save all my garage band songs to the cloud. They are about 1.5 gigs worth of a 5 gig free account. If I don't access them for a few weeks I find maybe one will be missing. This has happened 2 times in the past 6 months. Again it's not an issue where I gust ran out of storage ether locally or on my icloud, they just seem to disappear. Any thoughts?

    I have the same problem. It has happened twice in the last week. Nobody here has actually given a solution to the problem.
    Here are the particulars:
    -iPhone 4S
    -iOS version 7.0.4
    -Seems to only happen when I am home and the iPhone is synching with WiFi.
    -The problem begins with a dialog window on the phone that requests that I re-enter my iCloud credentials.
    -Within a few minutes/hours, all of the iCloud information is gone (contacts, calendars)
    -Email seems to still work for the iCloud and all other email accounts (gmail, hotmail, etc.)
    -The only way to get back the information is to re-boot the phone.
    -Prior to the dialog window, nothing out of the ordinary has taken place.
    -I am a little OCD, so I permanently close all running programs except for Mail, Messages, and Phone.
    -Programs running prior to the problem could be many but typically I use Waze while driving home, and I would have closed it after I pull in to the garage. (My iPhone gets WiFi in the garage)
    -The biggest drag is that when the contacts get cleared, any personal ringtones, or other identifiers get permanently cleared and have to be reassigned. That is the most annoying part.
    What else does anyone need to know? It seems to be a thing, so when (and I'm sure it will repeat) it happens again I will throroughly check all suggestions.
    I know how to fix it. I would like to know how to prevent it from ever happening again.

  • I have been noticing that when using the computer the mouse keeps going in places where I really do not want and just now select the sentence without I have done anything. Sometimes goes to places like bookmark or open tabs in website when I am reading a

    I have been noticing that when using the computer the mouse keeps going in places where I really do not want and just now select the sentence without I have done anything. Sometimes goes to places like bookmark or open tabs in website when I am reading a page.
    Also I have noticed opened windows that I have not opened.
    I have verified the sharing folder and also the remote access but it not let me turn it off.
    Also I have add a password to my computer and even using the same one it looks like is not working.
    The I photo stopped working, Mac Mail does not let me add rules (this is from one day to the other)
    The computer is mine, the internet I use is payed by me with a password. I did not give permission to anyone to use my computer or share my files.
    In system preferences in the sharing folder is showing everyone and staff.
    My computer is private I do not own a company and I do not have a network set up in my house.
    I had my photos removed from my computer and even after trying to reinstall I photo and fix the Mac Mail is not working.
    I am receiving emails saying that I have sent emails to people that I do not know and including in a time where I am working and not using the computer.
    Any suggestions in how to fix this issue?
    I really appreciate.

    With the multitude of issues you have I would take it to an Apple store or AASP and have them sort it out. Then I would sign up for Apple camp or one on one.

  • HT3702 I have paid once for one month subscription for al jazeera sport live app. I just released after few months that they are automatically charging me on monthly bases. How i can stop them charging me for something i did not use and i did not authoriz

    I have paid once for one month subscription for al jazeera sport live app. I just released after few months that they are automatically charging me on monthly bases. How i can stop them charging me for something i did not use and i did not authorize?

    You possibly set up an auto-renewing subscription with the app - there are instructions on this page on how to manage them, including how to stop them : http://support.apple.com/kb/HT4098

  • How to I get a link with a "Mail to" address to open up a Compose window in my Yahoo mail, rather than in the Mail progrom on my Mac. I do not use the Mac Mail program.

    How to I get a link with a "Mail to" address to open up a Compose window in my Yahoo mail, rather than in the Mail progrom on my Mac. I do not use the Mac Mail program.
    == This happened ==
    Not sure how often
    == always

    Thank you, "the-edmeister" -- You render a great service, one that lifts my spirits.
    Your answer also taught me to be a little more persistent, as I had started looking at Preferences, and just didn't notice the icons (including Applications) at the top of that window that would have led me to my answer.
    Dave

  • "you can not use multiple instance of Program at the same time"

    Hello @ all,
    I have a Problem, after the installing from Acrobat Testversion and acrobat reader in version in "all Combination" 8 an 9.
    I get this misstake information "you can not use multiple instance of Program at the same time" if I want open more then 1 .pdf.
    If I have no pdf open, but acrobat/reader so i can´t open with the same Misstake.
    I have deinstalled and installed, Allways I bekame the same information. I tryed all things to clean and know i don`t know forward.
    Important: by Drag an Drop in the Acrobat Reader it is going, but by direct click on the pdf i get mistake.
    Maybe, you know what I can do!
    Thanks for help!

    Installation of both Acrobat and Reader in the same Windows machine is not advisable. If I were you, I would remove both completely and then reinstall the one you want to keep.

  • I do not use and do not want an iCloud account and I keep getting requests to sign in....how do I stop the request?

    I do not use and do not want an iCloud account and I keep getting requests to sign in....how do I stop the request?

    If you bought the machine new yourself, and did not enter a password when configuring it, leave the field blank.
    If you bought it used, then you need to reset the password, as described here:
    Apple Article to reset the password

  • HT1476 ever since I upgraded to ios 7, the battery life is very short and I do not use my ipad all that much.l have been on the phone to apple 3 times, turning off all kinds of things I so not use and have powered off more than before but it is still poor

    ever since I upgraded to ios 7, my battery life is very short. I do not use the ipad all that much and have to charge it twice as much as before. I have been on the phone to Apple 3 times and turned off a number of things that I am not using and now power it off more regularly but still not happy with battery life. It is less than a year old and as I said, I don' t use it all that much

    My best bet would be to restore the phone. Back it up to itunes, and then reset it Factory settings. This way, any corrupt software will be removed, and you can start fresh. Make sure you back it up first. By the sounds of it, you are using the phone for business and probably need the data from it. Hope this helps!

  • I just downloaded a new version of OS7 to my iphone and when I try to sync with my mac book pro it will not finish and just spins around at the last step.  anyone help?

    I just downloaded a new version of OS7 to my iphone and when I try to sync with my mac book pro it will not finish and just spins around at the last step.  anyone help?

    It was telling you that you needed Mac OS 10.6.8 or later, not itunes 10.6.8
    Syncing with iTunes on a Mac or PC requires:
    Mac: OS X v10.6.8 or later"
    http://www.apple.com/iphone/specs.html

  • After backing up my iPod my applications will not reload and just shows waiting underneath the application any help?

    After backing up my iPod my applications will not reload and just shows waiting underneath the application, any help?

    http://lifehacker.com/5948155/fix-iphone-apps-stuck-waiting-during-installation
    http://alvinalexander.com/apple/iphone-waiting-apps-update-install-reinstall-del ete-ipod

  • Download the updated version of the software can not use and why?

    Download the updated version of the software can not use and why?

    It will help if you tell us what model of iPod touch you have, how and from where you downloaded the update, what version of iOS this update is, and details about the problem; "can not use" doesn't give us anywhere near enough information on which to base a diagnosis and offer suggestions.
    Regards.

  • HT201441 I currently own an iphone 5s buy from a foreign icloud but it is locked so I can not use and I do not know the previous owner who I can not contact them. iphone 5s have IMEI: **** gray TA & T's network ID: H. ..... @ m .... net. I need help so

    I currently own an iphone 5s buy from a foreign icloud but it is locked so I can not use and I do not know the previous owner who I can not contact them.
    iphone 5s have IMEI: **** gray TA & T's network
    ID: H. ..... @ m .... net.
    I need help so I can use the
    thanks so much for what
    <Edited By Host>

    Apple hasn't done anything. This is a security feature that you did not check to see had been properly de-activated before buying the phone.
    If there was a back door, it would be useless as a security feature.

  • HT1277 I installed mavericks today and the mail will not open and just keeps on not responding how do I get it back I have force quit it a number of times now

    I installed mavericks today and the mail will not open and just keeps on not responding how do I get it back I have force quit it a number of times now

    Open the system menu via Alt+Space or click the Firefox icon on the title bar and see if you can resize that window.
    If that works then close Firefox to save that setting.
    See also http://kb.mozillazine.org/Resizing_oversize_window
    Window sizes and positions are stored in [http://kb.mozillazine.org/localstore.rdf localstore.rdf] in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder].
    See http://kb.mozillazine.org/Corrupt_localstore.rdf

  • How do I agree to the terms and conditions on my iphone 5s for icloud. It does not agree, but just hangs

    When I go to Settings iCloud on my iPhone 5s I am prompted to agree to the latest terms and conditions. When I press agree the phone just hangs and I cannot agree to the latest terms and conditions. I am trying to change my apple id for iCloud which is incorrect on my phone, can anyone help. It is most annoying when I am prompted to log into icloud everytime I start my phone but I cant as I do not know the password to my old non existent email address.

    Welcome to the Apple community Linda.
    Have you tried deleting the account! restarting the device and trying again.

  • Adobe Premiere Pro CC does not open project - just hangs, no error message

    I've just finished editing a project in PP CC, saved it, then tried to reopen it and the program shows a blank page, then hangs.  I get no error message.
    The project is based off a PP 5.5 timeline.  It updates fine (and in fact I can open and convert the original timeline with no problem).  However, once I close the new version and try to reopen, this symptom occurs.
    I have updated my Creative Cloud software and it shows the Premiere Pro is up to date.
    My computer is an ASUS laptop running Windows 8.1 Pro
    i5 processor
    8GB RAM
    NVidea Geforce 610M+2GB graphics card
    Need help as I have to have this project output and uploaded by 8am tomorrow.

    This is a follow up to my original post and follow up.  I've now seen this issue several more times and realize it was not an issue with my USB drive.  It is an issue with the Dynamic Linking in Premiere.  I consider this a MAJOR BUG, so please note what I've found if you have an issue with archiving or opening projects done with previous versions of PP.
    The issue I've found is that Premiere seems to lock up trying to find dead media links.  If you've archived a project or moved files from their original position, Premiere CC cannot seem to find them.  The result is not a system hang up, but just a blank screen.  In some cases, after leaving it for a couple hours it found the media and continued.
    I've had a similar issue when trying to link 'dead' media with the actual files.  The system goes off into neverland.
    The work around I've found is to import the older jobs into a new Premiere CC project.  At that point, replace any dead links (do NOT try and find the media as you'll be lost in hangupville) by importing the media again and replacing the clip in the sequence with the new import from the bin.  Once all your media is 'live', remove any unused media from the project and confirm there are no 'dead' links (you can look at the media icon and notice a ? if they are not dynamically linked properly).  Manually clear any remaining unlinked media.  Save the project.
    I have started to use Project Manager to archive all Premiere projects when moving them from one server to another.
    This is a total pain in the @ss, and nothing I've seen before Creative Cloud.  I hope that Adobe gets this resolved or I may consider dropping my subscriptions completely.  That is a huge investment, but this type of issue is too much trouble to manage for a small production company.
    I welcome any other thoughts, fixes, or comments.

Maybe you are looking for

  • Determine Profit center in FI postings in Vendor rebate processing (MEU2)

    Hi ,     We are processing vendor rebates settlement using Tcode - MEU2 , the profit center getting assigned to FI document line is  common profit center and not the one specifically assigned to the material being processed in the Setllement document

  • Mini Bridge will not load in PSC5

    When I'm in photoshop cs5, and click on mini-bridge, it says it can't load.  Same with any other extenions I have. I've uninstalled the program.  Used MAC keeper, which is supposed to remove everything.  But I reinstall CS5, said it was installed, ev

  • Ive reinstalled firefox and cant figure out how to get to the search enging to set as my homepage help pls

    it all started with my missus daughter setting yahoo as the homepage when i had firefox as my hompage now i cant remember how to get it back to normal

  • Functions on iPod classic want work in reverse why?

    "I have an older iPod Classic 40gb click wheel. I have tried everyone one of the options suggested by Apple. The iPod will turn on and I can move forward in the menu. However after a song is selected I can not click foward or backwards or go to the m

  • WLI 8.1 SP2

    Hi, I need to do message sequencing in WLI 8.1 SP 2, is there any nice feature that WLI provides for managing this or do I have to do it manually? If manual, has anyone have some examples for me? Thank you, Wickes