Click to See Complete Forum and Search --> : Sending String to a Terminal
xxarmoxx
Jul 18th, 2007, 06:52 PM
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?
ComputerJy
Jul 18th, 2007, 07:47 PM
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
xxarmoxx
Jul 19th, 2007, 12:13 PM
To use this do I need to mess with router settings? or is it good to go as is?
ComputerJy
Jul 19th, 2007, 06:14 PM
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 :)
xxarmoxx
Jul 20th, 2007, 02:08 PM
Here is the code im working with right now: (Im leaving the serverName blank for security purposes)
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
ComputerJy
Jul 20th, 2007, 05:18 PM
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 transfernew String(inputBuffer, 0, 0, byteCount);Don't use deprecated methodsSystem.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: ObjectInputStream str=new ObjectInputStream(input);
System.out.println(str.readUTF());
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.