Results 1 to 6 of 6

Thread: Inter-thread communication with stdout

  1. #1
    Join Date
    Mar 2010
    Posts
    200

    Inter-thread communication with stdout

    Hello,
    I am currently developing a Linux application that asks me a few worries. In fact, I try to communicate with a Java application program in C.
    I try to use it to stdout: Here are the Protocol:
    - My C application (known as applicable) is launched by some java program (appliJava).
    - Applic sends its pid to stdout ( "pid: XXX") With a simple printf
    - AppliJava retrieves it.
    - Applic then sends information stdout. Also recovered by appliJava
    - The C program is stopped by sending a signal by USRSIG2 appliJava
    My main worry is that I do not receive any message (pid) to stdout in my java application and the program record works perfectly if it is not running. Do you have any solution for the same.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: Inter-thread communication with stdout

    Hello,
    I confess not to analyze your code, but I think the design is not good. From my point of view stdin and stdout are not suitable. Indeed, for two processes to communicate sockets seem much more independent of the target system and especially made for that. I guess you are getting the point and you will find alternate solution for the same.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: Inter-thread communication with stdout

    Hey
    Check out the following code, this may help you. If it fits your needs then you can use the following code
    Code:
    try {
    			Process = runtime.exec(new String[]{"applicant"});
    wait(10);
    		} catch (Exception e1) {
    			/ / TODO Auto-generated catch block
    			System.err.System.out.println("Please install the tool record");
     
    		}
    
    Thread thr =new Thread(new Runnable(){
    			Public void run(){
     
    				/ * Launch of the client * /
    				/ / Open the socket
    				try {
    					while(true){
    						Socket sock =new Socket( InetAddress.getByName(null),10001);
    BufferedReader buff = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    String str = buff.readLine();
     
    					
    						if(Online! =null & & Line! =""){
    							if(row.startsWith("pid")){
     
    							}else{
    								actions.add(row);
    System.out.System.out.println(row);
    							}
    						}
    						buff.readLine();
    					}
    				} catch (UnknownHostException e) {
    					/ / TODO Auto-generated catch block
    					e.printStackTrace();
    				} catch (IOException e) {
    					/ / TODO Auto-generated catch block
    					e.printStackTrace();
    				}
     
    			}
    		});
    thr.home();
     	}

  4. #4
    Join Date
    Mar 2010
    Posts
    200

    Re: Inter-thread communication with stdout

    Hello,
    Please check my updated code and if I am wrong somewhere then please guide me with the correct.
    Code:
    Thread t = new Thread (new Runnable() {
    			Public void run() {
    				/ * Process p to destroy * /
    				BuffereadReader buf = new BufferedReader(new InputStreamReader(getInputStream()));
    String str = "";
     
    				try {
    					while( ((str = buf.readLine()) != null)) {
    						/ / Process the output stream
    						if(str.startsWith("p")){
    							p = str.substring(4);
    System.out.System.out.println("p"+ str);
    						}else{
                                                    / / other than p
                                                    ....
                                                    }
    					}
    				} catch (IOException e) {
    					/ / TODO Auto-generated catch block
    					e.printStackTrace();
    				}
    			}
    		}
    		);
    t.home(); 
    	}

  5. #5
    Join Date
    Nov 2009
    Posts
    356

    Re: Inter-thread communication with stdout

    Hello,
    When you create a socket, there must be at the other end a server that listens on the port that you have dedicated. You have to start a small application server in your code before you create your socket. If you need more information on the socket and the serversocket then you can visit the suns' official site and there you can find the api on the java.io package. I think this will help you.

  6. #6
    Join Date
    Nov 2009
    Posts
    343

    Re: Inter-thread communication with stdout

    Hello,
    I do not think that this is a good idea to go with. Add a printf in your applicable once the server is launched, and in the print appliJava just before you create (or, I do not know ) Socket. Thus you will know if the server is launched. I think the program will be more effective if you are using the server and the seversocket concept that is the java.io package and its methods in your code.

Similar Threads

  1. Synchronize a producer thread and a consumer thread in C#
    By Ayuka in forum Software Development
    Replies: 6
    Last Post: 10-11-2010, 04:04 AM
  2. How to make Inter Thread Communicate with each other
    By afidelino in forum Software Development
    Replies: 3
    Last Post: 12-09-2009, 12:03 PM
  3. [Named Pipe] Redirection of STDIN and STDOUT
    By Shanbaag in forum Software Development
    Replies: 2
    Last Post: 24-04-2009, 03:53 PM
  4. How can I Redirect stderr into stdout ?
    By TALA in forum Software Development
    Replies: 4
    Last Post: 27-02-2009, 08:28 PM
  5. AMD Turion 64 X2 vs inter core 2 duo?
    By Samra in forum Motherboard Processor & RAM
    Replies: 7
    Last Post: 10-11-2008, 10:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,404,187.74509 seconds with 17 queries