How to make a c program "awaken" a java socket

I am developing a client program which has to communicate with a server written in c. I've created a listener thread which keeps verifying if there is anything in the stream:
public void run() {
    while(true) {
            try {
                if (input.ready()) {
                     msg = input.readLine();
.....the problem is that the client becomes obviously quite burdening for the cpu. Is there any way I could make the listener sleep and be awakened when the socket receives data from the c server?
I'd appreciate any kind of comments.
Thanks

Remove "if (input.ready())". readLine() will block, consuming zero cpu, until it gets data, EOF or an IOException.
I've been programming sockets since mid-80's and I've never used something like socket.ready(). The normal way to do sockets is either to read() / readLine() or to select() / poll(). ready(), available() and such should come with big blinking warning labels.

Similar Messages

  • How to make add the program system.out messages to a applet text field?

    How to make add the program system.out messages to a applet text field?
    System.out.println("I wanna displany this message on a applet text field, thanks");

    You may wish to change the output destination to a JTextArea. Please have a look at this link that likely shows what you want:
    [http://forums.sun.com/thread.jspa?forumID=54&threadID=640376|http://forums.sun.com/thread.jspa?forumID=54&threadID=640376]
    If you need other examples, search the forum. I found the search terms -- redirect system out textarea -- very helpful.
    Good luck

  • How to make a jar file from a java file?

    how to make a jar file from a java file, is there any one tht can help me thank you;

    You can study this.
    http://java.sun.com/docs/books/tutorial/jar/basics/index.html

  • How to make a data base connexion in java?

    I have an oracle 7 data base that i want to connect how to make a data base connexion in java?

    J
    D
    B
    C
    Search these forums or follow the JDBC tutorial

  • How to start an executable program from a java program ?

    Hi,
    does someone know how to start an executable program from a JAVA program ?
    Thanks, Fred.

    Take a look at the Runtime class.
    -S-

  • How to make a simple program in numbers that i can use on my iphone

    how can i make a touchable program in numbers that i can trasfer to my iphone and use out in the field of work? i am pretty good at excel sheets,but am still new with my macbook.

    Excel can't make an iPhone application, it can only make a spreadsheet. You would need an iPhone app capable of reading a spreadsheet produced by Excel.

  • How to make an ABAP program run for a specified number of times ?

    assalamoalikum all!!!
    Can some 1 plz tell me that How can I make my ABAP program run ONLY for 2 times (after it went in production etc)
    AND when the program runs for 2 times It then gets hanged/Locked foreever.
    Suppose my program is:
    REPORT twice002.
    write ' I will run only twice bye bye'.

    Well, I guess the only full proof way is to create a custom "Z" table which will hold the counter, in your program you would update this table every time the program runs. In this same program before updating the counter, you would retrieve the counter and check if it is = 2, if so, then write a message and RETURN.
    Regards,
    Rich Heilman

  • How to make in a program periodical​ly switched relay.

    I have a FP-1000(rs 232 controlled) with FP-DO-400 module.
    I need to switch it on(off) periodically. Something like switching it on every 30 seconds for 1 second.
    I just do not know how to make using LabView 7.0. I can control it switching manually but I'd like to make it automatically. Can someone give a couple of hints how to do it?
    Thanks.

    Hi,
    Thanks for posting your question on the NI forem.
    I have attached an example to make switching a simple boolean led on every 10 seconds for 1 "Minute"
    Essentially you would need a while loop, ever 10 sec the virtual led lights up in front panel the select vi resets the shift register every 10 sec and the loop exist after 60 sec (minute)
    Hope this helps!
    Thanks,
    Kurt App.Eng.
    Attachments:
    226838.vi ‏19 KB

  • How to make an exe file from a java class file

    i know one of the java's most powerfull properties is plataform independent, but if i have done one application (with GUI) that i want to run on Win32 for example, if anyone knows how to make it please send me a message to [email protected], how i know that can be make it? because HotJava is made in Java and in Win32 is a executable

    Do a search on these forums for any of the thousands of times this question has been asked and any of the thousands of times it's been answered.

  • How to make a frequencycount program??

    how would i make a frequency count program that requires me to keep count of the words that are entered like example
    Word Count
    cat 2
    dog 4
    rat 6
    Total 12
    Total of distinct words 3
    What steps would i have to take to make this program work?

    if i create my own class,how would i do that?Based on your posting history probably you would do it ineptly.
    Off you go then!
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.

  • How to make a modular program in java

    hello friends,
    i want to know that how i can make my program in a modular way.
    Thanks in advance
    Rakesh

    hello sir,
    thanks to notice me.
    modular program means, i have a large program which contains about 1500 lines. now i want to subdivide this program in multiple files and after call all files in a single main file . and want to run overall program from a single main file.
    regards,
    Rakesh

  • How to make inactive ABAP Program in production system

    Dear Expert,
    I have a lot abap program in production system which are not used anymore and my company plan to upgarde our SAP system, therefore to reduce the effort for the SAP upgarde I will  deactivate the unused ABAP program.
    My question how to change the active abap to inactive in production system ?
    Thank you in advance.
    Best regrads,
    Tjandiagung

    Program details are stored in the table REPOSRC.
    Primaray keys are PROGNAME and R3STATE.
    Suppose if the program zxy is in active state, then enry will be
    ZXY  A
    Suppose if we made some changes to it and saved, so the program is in inactive state. so one more entry will be there in the table
    ZXY A
    ZXY  I
    So if you add like this for the program which you want in the table REPOSRC, then that programs will be in inactive state.
    Regards,
    Nikhil

  • How to make a terminal program (similar to windows hyper-terminal but more powerful)?

    I am a new Labview user, Im trying to write a monitor program for use with uControllers. The main problem I cant seem to get over is to have a section of the screen where I can type in commands (that are sent only once!) then recieve a reponse from the uController directly under the command. Has anyone tried this?
    I am using the VISA read/write functions for serial communications, are these interrupt driven?, does anyone have ideas on this.
    Thanks in advance
    Dave Zdanowicz

    Hi,
    Doesn't your device maybe have an "echo"? Than, I guess, the easiest
    way would be to have two independently running VIs, one of which is
    repeatively checking the serial interace for incoming bytes and
    eventually displaying them in an apropriate indicator (e.g. a string
    indicator where all incoming new characters are appended to the old
    string via a shift register of a loop). The other VI then could be
    responsible for sending commands.
    It did something similar just resently. It works quite well. The
    command sending VI had some buttons to send kind of macros (several
    commands, often needed in combination, bundled together) and
    furthermore checked the keyboard with the keyboard VIs from the NI
    pages for additional inputs from the user, which were then just sen
    t
    to the serial interface byte by byte.
    Regards
    Arno
    On Tue, 17 Apr 2001 16:20:10 -0700 (PDT), Dave Z wrote:
    >I am a new Labview user, Im trying to write a monitor program for use
    >with uControllers. The main problem I cant seem to get over is to have
    >a section of the screen where I can type in commands (that are sent
    >only once!) then recieve a reponse from the uController directly under
    >the command. Has anyone tried this?
    >I am using the VISA read/write functions for serial communications,
    >are these interrupt driven?, does anyone have ideas on this.
    >Thanks in advance
    >Dave Zdanowicz

  • How do make sure a program has been completely removed?

    I'm trying to install Rosetta Stone but keep getting the message that a "newer version of the program already exists on this computer". I cannot find any sign of this. What am I missing?

    Does Rosetta Stone have its own uninstaller?  If so you should use that.
    If there is no uninstaller  look in your /Applications folder (on your boot drive) for the Rosetta Stone application.  At a minimum you could drag the application to the trash and then empty the trash.  There may be other stuff lying around from running the application (data, preferences, etc.) but that shouldn't be a problem.

  • How to make my "notepad-program" clean the textarea when clicking on "ny"

    Hi!
    I'm having a problem cleaning the textarea when clicking on "ny" (new) in the menubar. What am I doing wrong? Could someone help me solve this problem?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class AnteckningsProgram
                        implements ActionListener{     
              static JFrame frame;
              static JTextArea textArea;
         public void skapaVisaGUI () {
              frame = new JFrame ("Anteckningsprogram");
             frame.setSize (340, 240);
             frame.setVisible (true);
             frame.setTitle ("Ra Anteckningsprogram");
             Toolkit          tk = Toolkit.getDefaultToolkit ();
             Image      bild = tk.getImage("r.png");
             frame.setIconImage(bild);
              JTextArea textArea = new JTextArea ();
             frame.add (textArea, "Center");
             JMenuBar cm = createMenuBar();       
             //frame.add(cm, BorderLayout.NORTH);     
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public     JMenuBar     createMenuBar () {
              JMenuBar     menyBar;
              JMenu          meny;
              JMenuItem     oppna;
              JMenuItem     quit;
              JMenuItem     ny;
              menyBar = new JMenuBar ();
              JMenu arkiv = new JMenu("Arkiv");
              oppna = new JMenuItem ("Oppna");
              quit = new JMenuItem("Quit");
              ny = new JMenuItem("Ny");
              ny.setActionCommand("Ny");
              ny.addActionListener(this);
              quit.setActionCommand("Quit");
              quit.addActionListener(this);
              //arkiv.setMnemonic(KeyEvent.VK_U);
              arkiv.add(oppna);
              arkiv.addSeparator();
              arkiv.add(quit);
              arkiv.addSeparator();
              arkiv.add(ny);
              menyBar.add(arkiv);
              frame.setJMenuBar(menyBar);     
              return menyBar;     
         public void actionPerformed(ActionEvent e) {
             if ("Ny".equals(e.getActionCommand())) {
                      createTextArea();
                 //annars går vi vidare till metoden quit
                 else {
                     quit();
         protected void quit() {
                 System.exit(0);
         protected void createTextArea() {
              JTextArea textArea = new JTextArea ();
              textArea.setText("fdfdsfdfsdf");
          public static void main(String[] args) {
                  //anroppar metoden createandshowGUI
                  AnteckningsProgram ap = new AnteckningsProgram();
                  ap.skapaVisaGUI();
    }

    The basic problem here is 'scope'. The scope of an attribute is 'Java 101' by the way. I recommend you start on the basics *(<- link)* and leave GUIs aside for a while.

Maybe you are looking for

  • Macbook Pro doesn't boot from hard disk

    I recently applied an open firmware password to our Macbook Pro. A co-worker tried to boot via the t-funtion which obviously doesn't work when the open firmware password is active. He forget to contact me so he tried to get it to work using some star

  • Launching internet goes to Thanks for upgrading to Firefox 3.6.14, I want only Yahoo

    When starting internet I am led to a Firefox thank you page in the first tab and Yahoo in another tab. I only want Yahoo to display when joining the internet.

  • Help - Macbook Pro won't start after running update

    I just checked the FAQs here and ran several searches and have not found an answer to my problem. I sure hope someone here can help. Today I installed the big batch of updates Apple released recently (I think it was on July 31) on my 2.4 GHz Macbook

  • Safari and Quictime with dynamic innerHTML

    I'm working on a website that is doing some cool things with safari and quicktime. The site dynamically updates the media window with a new playlist using ajax, however redrawing the new QuickTime object in the same div causes multiple quicktime play

  • Audio Editing Program Unexpectedly Quits

    I'm not sure where else to post this since the Mackie forums clearly don't get looked at frequently. I did all the updates that apple has and I tried Mackie's Tracktion 3 and any time I open a project it unexpectedly crashes on me. and if I manage to