Sunday, 15 September 2013

Get an array from Server/Client app (Java)

Get an array from Server/Client app (Java)

So I have a Server/Client layer app running between my application and
database. I would like to get an array from the Server. I will paste some
pieces of code which I think is enough to give you an idea of what is
going on:
I send to the server the keyword for search in database (user and his
password)
fromUser = Musername + "," + Password;
out.println(fromUser);
Here is the code of the Server:
public class Server {
public static String[] theOutput;
public static String inputLine;
public static String[] string_array;
public static String output = "";
public static String[] process(String Input) throws Exception {
String[] data = Input.split(",");
// Call database class to get the results and store them into the
array
load_login pridobi = new load_login();
theOutput = pridobi.nalozi(data[0], data[1]);
return theOutput;
}
public static void main(String[] args) throws Exception {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.exit(1);
}
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);
BufferedReader in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
// get the username and password
inputLine = in.readLine();
if (inputLine.length() != 0) {
string_array = process(inputLine);
}
// And here I would like to do something like that :/
out.println(string_array);
}
}
PS: NOTE that some array elements are actually long text.

No comments:

Post a Comment