Running networking in background

Hi,
I've been working on a school project that needs networking, its a basic cafeteria program, where you can order from client pc's and your order is sent to the server where employees would see it. I'm having trouble making the server loop so that it i can receive unlimited orders, but it has to run in the background so that i can stop the server from a button
here is my coding: (its done in netbeans)
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
* @author Eben
public class ServerStatus extends javax.swing.JFrame {
    private final int PORT = 3308;
    ServerSocket servSock;
    Socket sock ;
private String e = "";
    /** Creates new form ServerStatus */
    public ServerStatus() throws IOException {
       class Task extends SwingWorker{
            @Override
            protected Object doInBackground() throws Exception {
              run();
              return null;
        initComponents();
    public void run() throws IOException
      while(sock.isConnected()){
                servSock = new ServerSocket(PORT);
                System.out.println("Waiting for a Connection ... ");
                sock = servSock.accept();
                System.out.println("Connection established with client " + sock.getInetAddress().getHostName());
                String reply = "Order was received";
                String echoLine, echoLine1, echoLine2, echoLine3, echoLine4, echoLine5, echoLine6, echoLine7, echoLine8, echoLine9;
                try {
                    System.out.println("1");
                    Scanner inFromClient = new Scanner(new InputStreamReader(sock.getInputStream()));
                    PrintWriter outToClient = new PrintWriter(new OutputStreamWriter(sock.getOutputStream()), true);
                    System.out.println("2");
                    echoLine1 = inFromClient.nextLine();
                    echoLine2 = inFromClient.nextLine();
                    echoLine3 = inFromClient.nextLine();
                    echoLine4 = inFromClient.nextLine();
                    echoLine5 = inFromClient.nextLine();
                    echoLine6 = inFromClient.nextLine();
                    echoLine7 = inFromClient.nextLine();
                    echoLine8 = inFromClient.nextLine();
                    echoLine9 = inFromClient.nextLine();
                    echoLine = echoLine1 + "\n" + echoLine2 + "\n" + echoLine3 + "\n" + echoLine4 + "\n" + echoLine5 + "\n" + echoLine6 + "\n" + echoLine7 + "\n" + echoLine8 + "\n" + echoLine9;
                    System.out.println("3");
                    JOptionPane.showMessageDialog(null, "Order from " + sock.getInetAddress().getHostName() + echoLine, "New Order Received", JOptionPane.INFORMATION_MESSAGE);
                    System.out.println("4");
                    outToClient.print(reply);
                    sock.close();
                    servSock.close();
                    servSock = new ServerSocket(PORT);
                    sock = servSock.accept();     } catch (Exception ex) {
                    System.out.print(ex);
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        StopServer = new javax.swing.JButton();
        jLabel1.setText("jLabel1");
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        StopServer.setText("Stop Server");
        StopServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StopServerActionPerformed(evt);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(301, Short.MAX_VALUE)
                .addComponent(StopServer)
                .addContainerGap())
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(266, Short.MAX_VALUE)
                .addComponent(StopServer)
                .addContainerGap())
        pack();
    }// </editor-fold>
    private void StopServerActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            sock.close();
            servSock.close();
        } catch (IOException ex) {
     * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new ServerStatus().setVisible(true);
                } catch (Exception ex) {
    // Variables declaration - do not modify
    private javax.swing.JButton StopServer;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration
}

The loop in the run method contains so many odd things, so I don't know where to begin.
E.g. why do you have a while loop that checks sock.isConnected(). What do you expect it to do? Why are you creating and closing a ServerSocket at each iteration? Why are you reading 9 lines? Why have you mixed UI and communication code?

Similar Messages

  • I am running my first time machine backup onto a Western Digital MyBook Live.  It is taking forever.  Is there antivirus software running in the background or any other settings I need to change to speed it up?  Also I am on a wireless network.

    I am running my first time machine backup onto a Western Digital MyBook Live.  It is taking forever.  Is there antivirus software running in the background or any other settings I need to change to speed it up?  Also I am on a wireless network.

    The initial Time Machine backup can certainly take a long time over wireless. Days, possibly. It's impossible for anyone here to be able to predict how long it will take, and wireless environmental conditions can change at any time.
    Is there antivirus software running in the background
    Only you can determine that. If you're using third party AV software, anything is possible.
    NAS devices may not be compatible with Time Machine, regardless of what their manufacturers may claim. Even after the Time Machine backup completes, your backup may be unreliable. You may not discover that until you need to rely upon the backup for some reason, and corruption can occur months or years from now.
    Time Machine supports the following backup configurations:
    A locally mounted volume
    Time Capsule
    A volume resident on a USB hard disk connected directly to a Time Capsule or current production AirPort Extreme Base Station.
    That's it. Any configuration other than the above list places you in an experimental category. If your backup fails, you're on your own.

  • HT1365 Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    Hi can anyone help with this issue regarding my wireless magic mouse? When im on google chrome and scrolling down the page i always have youtube running in the background but the audio cuts/spits/pops can anyone help me with this?

    The figures you mention only make sense on your intranet.  Are you still using the same wireless router.  The verizon one is somewhat limited as far as max wireless-n performace.  For one thing it only has a 2.4 radio.   I like many people who wanted wireless-n performance before they even added a wireless-n gigabit router, have my own handling my wireless-n network.

  • Cisco mobile does not running in the background ont my ipad

    Hi
    I have a Cisco Callmanager 7.1.5, an ASA5510, an Iphone and an Ipad
    I have configure the VPN on my iphone and my ipad and I can make a VPN connection to the ASA through the WIFI
    I have configure the  Cisco Mobile 8.1.2.3245 on my iphone and my ipad.
    If the application is open, I am connected to the CCM and I can make and receive calls.
    On the iphone when the application is  running in the background, its good I can receive calls
    On the ipad when the application is running in the background, I can't receive calls, I am unregistered
    On the ipad, if I disconnect the VPN, and make a WIFI connection on my local network. When the application is running in the background, I can receive calls.
    It is an ipad2 with iso 5.0.1 (9A405)
    I reverse the ID of the IPAD and IPHONE, and it is the same.
    The problem is only on the IPAD when there is my VPN connection
    Could you help me?
    Thanks
    nicolas

    A double click on the Home button will reveal a tray containing all apps that are currently running (suspended?).
    Side swiping this will reveal as many as are active, with a swipe to the right when on the first display will reveal further controls for the iPad, mainly relating to the iPod part, but also containing a screen lock option I believe.
    Click and hold any one of them till they 'jiggle' and show a - you can then click this to remove it, relaunching the app as required in the normal way.
    Regards,
    Colin R.
    Message was edited by: Colin Robinson
    PS Tap the Home button once to get out of this mode.

  • Help trying to get the F_ApiWinConnectSession initialized and running in the background.

    Fellow FM Developers,
    I have the FDK8 and have been using framemaker as a processor of templates. We have successfully written a program that uses the framemaker in a user account currently logged in. In other words, USER A logs in with their account on Computer A and processes files just fine.  Now, we would like to set up a system where jobs are submitted by USER A and runs on a remote Computer B which processes the document and saves it as a PDF.
    We want to make it so users can submit a job through a web service using the .NET framework. We have tried to do this, however we are failing on one crucial part of our development. I am trying to use the single most important (asynchronis) connectivity line:
    F_ApiWinConnectSession( NULL, NULL, &ClassID );
    This is because we want to have framemaker start in the background with this execution of this service.  Unfortunately, without the GUI available this command fails.  We have obviously created a Progid and it has been registered in the registry. We did this by runnning :
    FrameMaker.exe /progid:FrameMaker.Automation.2 /auto
    Can anyone help me with trying to get framemaker to run in a background.  Is there a way to process the documents without have the GUI up and loaded and then have it process the document.
    Your help is greatly appreciated,
    Adam

    Adam,
    The server license is more tuned to the type of output that you are creating, regardless of the number of users. If you are creating content from external sources and generating a PDF in an automated way via FM, then you need a server license (period).
    Read your FM EULA carefully.
    2.2.  Limitations on Server and Network Use.  You may install one copy of  the Software on your Computer file server for the sole purpose of downloading  and installing the Software onto other Computers within your internal network up  to the Permitted Number, provided that the total number of users that are  permitted to download and install the Software from such Computer file server,  does not exceed the Permitted Number.  Except as explicitly described above, no  other network or server use is permitted under this license, including but not  limited to, using the Software either directly or through commands, data or  instructions from or to any other Computer, for internet or web hosting services  or by any user not licensed to Use this copy of the Software through a valid  license from Adobe.  For the avoidance of doubt, this Agreement does not permit  the Software to be Used in any batch-oriented environment where such Use of the  software is to produce Postscript or PDF output from data originating from any  other application, unless such Use is merely incidental to a Use clearly  permitted by the license.To obtain rights for additional server, batch oriented  or network licensing uses, you may purchase a license(s) for the FrameMaker®  Server product. The FrameMaker Server product license is available for review  at, http://www.adobe.com/products/eulas/main.html.
    This has greatly impacted the database publishing side of things. If all of  your content is completely created in FrameMaker, then you should be ok.  However, if you create or get any content outside of FrameMaker and pass it  through FM to make your documentation sets, then according to Adobe, you need to  be using the FrameServer product (for creating the PDFs).

  • My macpro runs slow with or without internet on..... How can I find out if something is running in the background?

    my macpro runs slow with or without internet on..... How can I find out if something is running in the background?

    Please boot in safe mode and test. Still slow? If you connect to a wireless network, you may have to connect with Ethernet in safe mode.
    After testing, reboot as usual (not in safe mode.)
    Mac OS X: Starting up in Safe Mode

  • How can I know what apps are running in the background of Q10

    My battery is not lasting more than 12 hours even though I'm moderately using it. How can I tell which applications are running in the background?

    As of now, the BB10 does not allow any apps to run in the background unless they are baked in the OS or in the active frames. So if an app is not in a active frame, no app is running in the background. try maximizing your battery by switching to wif whenever you have a wifi network.
    Twitter: @ukmight
    1. Click on the " Like " button if you find anything helpful posted.
    2. If any of the replies in your post has resolved your problem, mark the reply(ies) as " Solution ", so that others can readily view the solution instead of creating another redundant post.

  • My IPhone4 is secretly using alot of data even though I have double tapped Home button and closed all the apps running in the background.

    My Iphone4 is secretly using alot of data even after I have double tapped the home button and closed all the apps running in the background.
    This just started happening 3 days ago.
    When im out of home, the phone drains battery REALLY FAST, I lose 6% battery in 5 minutes.
    The phone also heats up and feels very warm after a few minutes.
    When I turn the data plan off, it becomes normal again, like I lose 1% every 30minutes even while listening to mp3.
    I can conclude that its secretly using the 3G at an alarming rate which causes the battery to die so quickly
    I have uploaded 2 pictures showing what happens before and after I turn on my WIFI.
    Notice that the ping spikes like crazy on my home network once I turn on my WIFI on my IP4
    WIFI OFF:
    WIFI ON:
    I hope someone can assist me with this!
    Thanks!!

    chuuburg wrote:
    My Iphone4 is secretly using alot of data even after I have double tapped the home button and closed all the apps running in the background.
    This just started happening 3 days ago.
    There is a common misconception that closing an app on the Quick Launch screen (it's real name) also kills the app's background process. This is not the case. First, all built in apps (mail, contacts, calendar, game center, notes, reminders, Genius, Photo Stream, etc) continue running their background processes even if killed in the Quick Launch screen. For apps from the App Store killing the foreground process also gives the app the option of killing its background process, but it doesn't have to. In addition, any app that has Notifications enabled can restart its background process if it receives a Notification.
    iOS 7 gives the user more control over background processes; you can selectively allow or deny any app to run in background. As you apparently have not upgraded this option is not available to you.
    As Chris has already told you, there's an app on your phone that is stuck in a loop. As you discovered killing foreground processes did not resolve the problem. One trick that sometimes resolves this is to let the battery run down until the phone shuts off and will not restart. Then charge to 100%.

  • Firefox is diverting searches to other sites. there also seems to be an ad site running in the background

    google searches links get diverted to other sites. There is some sort video/ audio stream running in the background. I think it comes from blinx. I looked at my add on and they all seem legit.

    Install, update, and run these programs in this order. They are all free for personal use, but some have limited functionality in the "free mode" - but those are features you really don't need to find and remove the problem that you have. <br />'''''(Not all programs detect the same Malware.)'''''
    Malwarebytes' Anti-Malware - [http://www.malwarebytes.org/mbam.php] <br />
    SuperAntispyware - [http://www.superantispyware.com/] <br />
    AdAware - [http://www.lavasoftusa.com/software/adaware/] <br />
    Spybot Search & Destroy - [http://www.safer-networking.org/en/index.html] <br />
    If these don't find it or can't clear it, post in one of these forums for specialized malware removal help: <br />
    [http://www.spywarewarrior.com/index.php] <br />
    [http://forum.aumha.org/] <br />
    [http://www.spywareinfoforum.com/] <br />
    [http://bleepingcomputer.com]

  • How do I find out what applications are running in the background

    I have a 2008 iMac with 2GB memory.  How do I find out what programs are running in the background?  I am going to buy a new iMac before the end of the year to replace this one.  When I looked at Activity Monitor it shows 1.8Gb used but doesn't tell all the programs running.

    open activity monitor [if it doesnt launch click winders>Activity Monitor]. then it'll show all proceses

  • Adobe Bridge not running in the background

    I have bridge setup to load and run in the background when I start windows.  However it doesn't run in the background but launches and runs as normal.the icon does not load in the control panel as does other programs that load and run in the background. Running a 64bit windows 7 machine

    Ashutosh.Nigam wrote:
    If you want to  start Br at login, Follow below mentioned steps:
    In Bridge , choose Edit > Preferences (for Windows) or Adobe Bridge > Preferences (for Mac OS).
    Choose Advanced.
    Select Start Bridge At Login.
    You can disable this option at any time, Hope this helps.
    I don't have CC but others say the standard option is not there.  Can you confirm it is?

  • When I click on a new link, it opens a whole new firefox instead of using my default which is running in the background

    I have firefox as my default browser. Anytime I click on an email or search for something, instead of opening my default browser, firefox loads a new firefox page. It is a blank page just as if I had never had one. It has nothing on it except how you would start out before you set up your tabs and history etc. My default firefox is still there running in the background but I must click on it and manually put in the link I was trying to open.
    Any suggestions.

    Some added toolbar and anti-virus add-ons are known to cause
    Firefox issues. '''Disable All of them.'''
    Start '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Firefox in Safe Mode]''' {web Link} by holding down the '''<Shift ''(Mac Options)'' >''' key, and then starting Firefox. Is the problem still there?

  • When running the workflow background process for drop shipment order, sale order line's status gets automtically closed instead of awaiting shipping

    Hello friends,
    I am created a drop shipment order with all the setups done . now i have booked the sale order as source type external. but when i run the workflow background process , after completing the report when i check the sale order line status it changes to "closed" instead of "awaiting shipping".
    Plz guide me if i have missed something in the setups.
    thanks,
    Sachin

    Hi Sachin,
    pls check the below notes from MOS
    Drop Ship Sales Order Cycle In Order Management (Doc ID 749139.1)
    Vision Demo - How To Create A Drop Ship Sales Order/Purchase Order (Doc ID 1060343.1)
    Thanks
    -Arif.

  • Can the width of a report that has been run in the background be increased?

    Hello Experts,
    How can I increase the width of a report that I have run in the background so that it does not wrap text to the next line?
    I have been running the same HR report successfully in the background for many months.  Today I ran it with the same parameters that I've always used and when I retrieve it from my Own Job Spool - System | Own Spool Request | Display Contents the last field is wrapped to the next line.
    Thanks.
    Regards,
    Jeanette

    Jeanette,
    Thereu2019s another possibility if Tedu2019s suggestion doesnu2019t work. When you look at your spool requests, thereu2019s an icon on the toolbar next to the eyeglasses that looks like a yellow rectangular callout. Itu2019s called u201CDisplay in Maximum Widthu201D. Select the Spool no. to display and then press this icon. Shift + F4 is the shortcut.
    Regards,
    Howard

  • The application does not use the  screen and run in the background

    Hi
    I have downloaded a package of j2me Midlet
    from [link] here [link]
    and try to reuse the code
    but I get the following error when running the code:-
    The application does not use the screen and run in the background
    I think the error into one of these two classes
    package main;
    import javax.microedition.midlet.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import java.io.IOException;
    import java.io.InputStream;
    public class MainMidlet extends MIDlet implements CommandListener {
        private SSGameCanvas gameCanvas ;
        private Command exitCommand ;
        private Player player = null;
        public void startApp() {
      try {
           //   create new game thread
              gameCanvas = new SSGameCanvas();
              gameCanvas.start(); // start game thread
              exitCommand = new Command("Exit",Command.EXIT,1);
              gameCanvas.addCommand(exitCommand);
              gameCanvas.setCommandListener(this);
                Display.getDisplay(this).setCurrent(gameCanvas);
       catch (java.io.IOException e)
                e.printStackTrace();
            try {
                // start sounds
                InputStream in = getClass().getResourceAsStream("/resource/startfly.wav");
                player = Manager.createPlayer(in,"audio/x-wav");
                player.setLoopCount(1);
                player.start();
            catch (MediaException ex)
                ex.printStackTrace();
             catch (IOException ex)
                ex.printStackTrace();
        public void pauseApp() {
        public void destroyApp(boolean unconditional) {
            if (player != null) {
                player.close();
            System.gc();
      public void commandAction(Command command, Displayable displayable) {
           if (command == exitCommand)
                 destroyApp(true);
                 notifyDestroyed();
    package main;
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    public class SSGameCanvas extends GameCanvas implements Runnable {
        protected GameManager gameManager;
        protected boolean running;
        private int tick=0;
        private static int WIDTH;
        private static int HEIGHT;
        private int mDelay = 20;
        Form mainForm;
        Display display;
        //private int MaxTime;
        public SSGameCanvas() throws IOException{
            super(true);
            gameManager = new GameManager(5,5,getHeight()-10,getWidth()-10,this);
        public void start() {
                this.running = true;
                Thread t = new Thread(this);
                t.start();
        public void stop() {
            running = false;
        public void render(Graphics g) {
            WIDTH = getWidth();
            HEIGHT = getHeight();
            // Clear the Canvas.
            g.setColor(0, 0, 50);
            g.fillRect(0,0,WIDTH-1,HEIGHT-1);
            // draw border
            g.setColor(200,0,0);
            g.drawRect(0,0,WIDTH-1,HEIGHT-1);
            // draw game canvas
            gameManager.paint(g);
        public void run() {
            while (running) {
                // draw graphics
                render(getGraphics());
                // advance to next graphics
                advance(tick++);
                // display
                flushGraphics();
                try { Thread.sleep(mDelay); }
                catch (InterruptedException ie) {}
        public void advance(int ticks) {
            // advance to next game canvas
            gameManager.advance(ticks);
            this.paint(getGraphics());
    }Edited by: VANPERSIE on Jul 10, 2012 12:26 PM

    Hi Andi,
    Thanks for your reply.
    Yes, I have waited for a while and the result doesn't change.
    The Porblem here is the application is seen started in visual administrator.Only restart brings up the page back.
    Can you please suggest anything.
    Thanks and regards
    Nagaraj

Maybe you are looking for