///////////////////////////////////////////////////////////////////////////////
//Copyright (C) 2015 Joliciel Informatique
//
//This file is part of Talismane.
//
//Talismane is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//Talismane is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Affero General Public License for more details.
//
//You should have received a copy of the GNU Affero General Public License
//along with Talismane.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////
package com.joliciel.talismane.examples;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.nio.charset.Charset;


/**
 * A class showing how to communicate with Talismane running in client/server mode.<br/>
 * Before running this class, start Talismane in server mode via:<br/>
 * <pre>java -Xmx2G -jar talismane-core-X.X.Xb.jar languagePack=frenchLanguagePack-X.X.Xb.zip command=analyse mode=server encoding=UTF-8</pre>
 * 
 * Next, assuming you have compiled the present project via javac, try the following command<br/>
 * <pre>
 * java com.joliciel.talismane.examples.TalismaneClient localhost 7272
 * </pre>
 * 
 * Type as many sentences as you like (note that a Windows console might not handle accents very well).<br/>
 * When you're finished, type a carriage return without any text. At this point, the server will analyse the sentences.<br/>
 * 
 * You can try the same command several times, showing that the server is in listening mode.<br/>
 * 
 * @author Assaf Urieli
 *
 */
public class TalismaneClient {
	public static void main(String[] args) throws IOException {

		if (args.length != 2) {
			System.err.println(
					"Usage: java com.joliciel.talismane.examples.TalismaneClient <host name> <port number>");
			System.exit(1);
		}

		String hostName = args[0];
		int portNumber = Integer.parseInt(args[1]);

		// open socket to server
		Socket socket = new Socket(hostName, portNumber);
		OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream(), Charset.forName("UTF-8"));
		BufferedReader in = new BufferedReader(
				new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8")));

		BufferedReader stdIn =
			new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
		String fromServer;
		String fromUser;

		// Get next input from the user, ending with a blank line
		String input = "\f";
		while ((fromUser = stdIn.readLine()) != null) {
			System.out.println("Client: " + fromUser);
			if (fromUser.length()==0)
				break;
			input += fromUser + "\n";
		}
		
		// end input with three end-of-block characters to indicate the input is finished
		input += "\f\f\f";
		
		// Send user input to the server
		out.write(input);
		out.flush();

		// Display output from server
		while ((fromServer = in.readLine()) != null) {
			System.out.println("Server: " + fromServer);
		}

		socket.close();
	}
}

@@ -1111,17 +1111,16 @@
 arset;%0A%0A
-%0A
 /**%0A * A
@@ -1188,24 +1188,27 @@
 lient/server
+%0A *
  mode.%3Cbr/%3E%0A
@@ -1278,24 +1278,28 @@
 a:%3Cbr/%3E%0A
+ * %0A
  * %3Cpre%3E
 java -Xm
@@ -1290,16 +1290,20 @@
  * %3Cpre%3E
+%0A * 
 java -Xm
@@ -1311,96 +1311,76 @@
 2G -
-jar talismane-core-X.X.Xb.jar languagePack=frenchLanguagePack-X.X.Xb.zip command=analyse
+Dconfig.file=%5BlanguagePackConfigFile%5D -jar talismane-core-X.X.Xb.jar
  mod
@@ -1402,16 +1402,20 @@
 ng=UTF-8
+%0A * 
 %3C/pre%3E%0A 
@@ -1491,16 +1491,19 @@
  try the
+%0A *
  followi
@@ -1518,16 +1518,20 @@
 nd%3Cbr/%3E%0A
+ * %0A
  * %3Cpre%3E
@@ -1692,16 +1692,19 @@
 ight not
+%0A *
  handle 
@@ -1808,16 +1808,19 @@
 s point,
+%0A *
  the ser
@@ -1936,16 +1936,19 @@
 er is in
+%0A *
  listeni
@@ -2141,14 +2141,8 @@
 tln(
-%0A%09%09%09%09%09
 %22Usa
@@ -2550,21 +2550,16 @@
 dReader(
-%0A%09%09%09%09
 new Inpu
@@ -2650,20 +2650,17 @@
  stdIn =
-%0A%09%09%09
+ 
 new Buff
@@ -2962,10 +2962,12 @@
 th()
+ 
 ==
+ 
 0)%0A%09
@@ -3009,18 +3009,16 @@
 n%22;%0A%09%09%7D%0A
-%09%09
 %0A%09%09// en
@@ -3084,16 +3084,21 @@
 input is
+%0A%09%09//
  finishe
@@ -3120,18 +3120,16 @@
 f%5Cf%5Cf%22;%0A
-%09%09
 %0A%09%09// Se

Update javadoc usage instructions for TalismaneClient/Server setup