Progress with AI implementation.

[Enter Post Title Here]


Purpose: 2

1- Prepare Unix Server 3

2- Develop Server Program 5

3- Develop Client Program 6

4- Test Program 8

5- Sentiment Analysis using JAVA API (TBD) 9


The purpose of this code is analyzing sentiment of a client or subject as part of The Content Theory Posttraumatic Growth project.

Score > 0. Is positive and below 0 is negative. Store the data for each candidate for later experiments.

  1. 1- Prepare Unix Server
  2. i. Setup Amazon EC2 Linux Instance
  1. ii. Open firewall for socket programming for the server instance. We are going to use 9090
  1. iii. Assign to  (optional)

Verify port is open using telnet (used windows machine)

If you don’t see error and blank screen displayed, it means port is opened.

‘Ctrl’ key and push the ‘] and type quit to exit.

  1. iv. Use Putty to login 
  1. v. Install java  and JDK 

sudo amazon-linux-extras enable corretto8

sudo yum install java-1.8.0-amazon-corretto-devel

#verify installation

java -version

Now the server is ready with Java installed and port 9090 opened.

  1. 2- Develop Server Program

User any Desktop IDE to develop Java server program. Compile and copy to server

In this exercise, I have used MS-Code to develop the code and compiled in Windows machine. The transferred to amazon Linux 2 system using WinSCP.

  1. 3- Develop Client Program

Develop a client Socket Program to connect with server 

port: 9090

/* File is: Sasikumar Manickam 2019


import*;  // Get the Input Output libraries

import*; // Get the Java networking libraries

public class sasiClient{

  public static void main (String args[]) {

    String serverName;

    if (args.length < 1) serverName = “”;

    else serverName = args[0];

    System.out.println(“Sasi’s Simple Socket Client.\n”);

    System.out.println(“Using server: ” + serverName + “, Port: 9090”);

    BufferedReader in = new BufferedReader(new InputStreamReader(;

    try {

      String name;

      do {


    (“Enter a string and the server will echo it back to you. Use [quit] to stop client: “);

  System.out.flush ();

  name = in.readLine ();

  if (name.indexOf(“quit”) < 0)

    getReply(name, serverName);

      } while (name.indexOf(“quit”) < 0);

      System.out.println (“Cancelled by user request.”);

    } catch (IOException x) {x.printStackTrace ();}


  static void getReply (String ToServerString, String serverName){

    Socket sock;

    BufferedReader fromServer;

    PrintStream toServer;

    String textFromServer;


      /* Open our connection to server port, choose your own port number.. */

      sock = new Socket(serverName, 9090);

      // Create filter I/O streams for the socket:

      fromServer = 

  new  BufferedReader(new InputStreamReader(sock.getInputStream()));

      toServer   = new PrintStream(sock.getOutputStream());

      // Send string to the server:

      toServer.println(ToServerString); toServer.flush(); 

      // Read up to 3 lines of response from the server, and block while synchronously waiting:

      for (int i = 1; i <=3; i++){

  textFromServer = fromServer.readLine();

  if (textFromServer != null) System.out.println(textFromServer);



    } catch (IOException x) {

      System.out.println (“Socket error.”);

      x.printStackTrace ();





  1. 4- Test Program

Download client

Unzip and run sasiClient.class using java sasiClient command

  1. 5- Sentiment Analysis using JAVA API (TBD)

Modify server code to call Google sentiment Analysis


// Imports the Google Cloud client library





// Add class to call google API

  Private static void analyseSentiment(String inputText) throws Exception {

    // Instantiates a client

    try (LanguageServiceClient language = LanguageServiceClient.create()) {

      // The text to analyze

      String text = inputText;

      Document doc = Document.newBuilder()


      // Detects the sentiment of the text

      Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();

String score = 

String magnitude = 

return “Score:” + sentiment.getScore() + “Magnitude:” + sentiment.getMagnitude();