Results 1 to 6 of 6

Thread: Sending String to a Terminal

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Sending String to a Terminal

    Here is what Im trying to do:

    I created an app that creates special queries. How can I have my java app automatically send those created queries directly to a terminal window? or it can directly connect to the ftp server and send the query and return output. Is this possible?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Sending String to a Terminal

    It's just a simple client server application.
    You need a "Socket" Connection between the 2 terminals.

    You will need to use the classes:
    java.net.ServerSocket
    java.net.Socket
    To establish the client-server connection
    You'll also need the classes:
    java.io.ObjectInputStream
    java.io.ObjectOutputStream
    to transfer data between both terminals
    I've seen an example to create a simple messenger using simple TCP/IP connection between 2 computers and the Client-Server approach for some reason. try searching the web, I guess you'll find more useful samples
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: Sending String to a Terminal

    To use this do I need to mess with router settings? or is it good to go as is?

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Sending String to a Terminal

    Not necessarily. It depends on whether your current configuration, I don't think I can answer this question for you. But a simple test should do it
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: Sending String to a Terminal

    Here is the code im working with right now: (Im leaving the serverName blank for security purposes)


    Code:
                String	serverName = "";
        int	portNumber = 22;
    
        Socket	server = null;
        
        try
        {
        server = new Socket(serverName, portNumber);
    
        
           
        InputStream	input = server.getInputStream();
         
        
        
        int		byteCount;
        byte		inputBuffer[] = new byte[1024];
    	
        while ((byteCount =  input.read(inputBuffer, 0, 1024)) != -1)
        {
          String	stuff = new String(inputBuffer, 0, 0, byteCount);
          
              System.out.println("Received: " + stuff);
      
        }
        } // end try
        catch (Exception e) { System.out.println(e.toString()); }
            
        System.out.println("done");
    And here is the output im getting:

    Received: SSH-2.0-OpenSSH_3.9p1

    done
    and it takes about 2 minutes to go from the first line to 'done'. Any idea on whats going on? How can I send a command? I need to login some how too, not sure how to do that. Thanks

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Sending String to a Terminal

    Code:
    int portNumber = 22;
    Are you sure this port number is not being used by another service? this might be the reason for a slow data transfer
    Code:
    new String(inputBuffer, 0, 0, byteCount);
    Don't use deprecated methods
    Code:
    System.out.println("Received: " + stuff);
    If more than 1 KB is being read, the word "Received" will be printed over and over

    try using the following code:
    Code:
    	    ObjectInputStream str=new ObjectInputStream(input);
    	    System.out.println(str.readUTF());
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width