I have a use case where we have two different java programs doing:
First java program has to send some parameters to invoke the second java program.
First java program has to send datastream to the second program.
The approach that I have in mind is:
Use Socket class where second java program is socket server and first java program socket client.
First java program serializes the arguments needed by second java class to initialize it's class object that performs the task. Second java program de-serializes it.
Now the first java program has to send data that second java program on another machine would work on. The First program can send data as a BufferedWriter object but how will server know that it is receving the arguments and after arguments, it has got the stream to work on ?
Any other inputs for the approach are greatly appreciated !
Thanks
check out here, its nicely explained.
http://download.oracle.com/javase/tutorial/networking/sockets/readingWriting.html
Related
I've been trying to make a monitor java program that prints out some stats from concurrent threads while taking user input at the same time. And the problem i'm facing is that if a user was writing a long command "create file /home/user/etc" for example and a concurrent thread happened to print out some messages in the middle of his command. his command would be cut in half which i know won't effect the actual input i get but it ruins the user interface.
A terminal picture to illustrate the problem
in this picture i was atempting to write "why does this keep being interrupted????" and you can see what happens.
so how can i separate the command line from the output so it doesn't get interrupted while keeping both on the same window?
I am using bash on Putty if that's relevant.
I appreciate all help.
As far as I can discern, what you're trying to do isn't possible. You have a few different options that I can think of:
1) Use a ncurses java library (such as jcurses).
2) Only write out data to a file.
3) Create a java GUI with separate input and output text fields/areas.
I have a Java script - with a function that I wrote, that I send her a list of strings, the function encrypt each element, and returns a list with the encrypted elements.
My problem is this:
I need to use this function in a python script (send a "list" Python object as input, and receive an "ArrayList" Java object).
How can I call a Java function - that I wrote, in a python script?
And does the list objects are consistent between Python and Java (list Vs. ArrayList)?
A big thank you to all!
** Edit: I'm about to use this entire package in AWS Lambda Function **
The main decisions for choosing a solution seem to be
What do we use to execute the Java program?
How do we transfer computed data from the Java program to the Python program?
E.g. you could decide to use a Java JVM and execute via a call to the operating system from Python.
The computed data could be sent to standard output (in some suitable format) and read in and processed by Python. (See link for the os call and i/o)
I am using TCP Sockets and I am a beginner in Java and Sockets too. The scenario is that the client,depending on server 's answer, may send either int or a string. I need to save the output stream of the client, in a variable on the server 's side, so i can use it in if statements and so on. But how could I do this when i don t know if the stream sent is an integer or a string?
I have made a very simple example, because my code is huge and messy and i don t want to make it more complex
Client Side:
serverSentence=inFromServer.readLine();
if (serverSentence.equals("Hello"))
{
anInt=readUserInput.nextInt();
outToServer.write(anInt);
}
else
{
outToServer.writeBytes("Hello word!"+'\n');
}
So how I could do this, I mean saving in a variable the Client 's output stream, in the Server 's side (or the opossite), so I could use it in loops and ifs?
Use Object. A reference typed as an Object may refer to Integer or String. Another story is of course deserializing the incoming data as either. If the problem has to do with not knowing how to interpret serialized data, include some sort of flag to indicate what the data is.
You should design your protocol of communication between server and client in such a way that server would be able to read some information (you could call it standard header), and based on that would know how to interpret the remaining bytes sent by the client.
And then you'll know how to read the data from client, and where to store it.
I have two javascript files:
http://www.dublinbikes.ie/design/marseille/javascript/gmaps_common.js
http://www.dublinbikes.ie/design/marseille/javascript/gmaps_search_station.js
Which for http://www.dublinbikes.ie/All-Stations/Station-map# website
What I want to do is to simulate the search a station status action that on the left hand side by set variable 'value' a station number and pass it to gmaps_common.js for execute, then read the result from gmaps_search_station.js that executed variable called html from LeftBlock(id) function.
Because I need run whole process automatically several times, so please suggest me could I use Java to do this and how.
Thank you very much for the help.
You should never try to emulate a JavaScript interpreter just to get js variables out of it - just do the same thing the script would do in your language. Java is mighty enough.
The script just gets a list of stations from http://www.dublinbikes.ie/service/carto, and then queries details from http://www.dublinbikes.ie/service/stationdetails/dublin/{number} (example). Java has lots of HTTP and XML libraries, it will be no problem for you to do that, too.
I have to take one input from console in first java program. That input i have to pass in second java program which is getting executed as thread from the main method of first java program.
I made the variable as static and tried accessing in second java program but it is showing null value(default value).
I am not supposed to make the object of first program also.
Please suggest me how to do?
If your first java program is starting the second using O.S.-like functions that produces the same effect as if you were starting from the console, then you will have a second instance of the JVM, with everything "reseted". That's why you're getting that null.
A suggestion would be passing the value as a parameter for the second program.
As far as I know there's no shared memory mechanism implemented in Java. Pipes also don't work across VM boundaries, so you would have to use the JNI and C code to create a mechanism.
But then if the two programs cooperate that close together, why not let them in one VM and use threads? Security reasons is the only thing I could think of.