title: Set variables to client socket
body: <p>I'm making a Java TCP Server and a noob question that I can't revolve came to me, what's the way to set variables to the current client socket? Check class Handler, code above may be not important.</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import java.io.IOException;
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.logging.Handler;
  
  public class tcp_server {
    public static void main(String[] args) {
      int count = 0;
  
      ExecutorService executor = Executors.newFixedThreadPool(30);
      Socket client;
  
      try {
        ServerSocket server = new ServerSocket(8080);
  
        while(true) {
          client = server.accept();
          executor.execute(new Handler(client));
        }
      }
      catch(Exception e) {
        System.out.println(e);
      }
    }
  
    public static class Handler implements Runnable {
      private Socket client;
  
      public Handler(Socket client) {
        this.client = client;
      }
  
      public void run() {
        try {
          BufferedReader inFromClient = new BufferedReader(new InputStreamReader(client.getInputStream()));
          DataOutputStream outToClient = new DataOutputStream(client.getOutputStream());
          String event = inFromClient.readLine();
          System.out.println(event);
  
          // Arrays.copyOfRange(byte[] original, int from, int to)
  
          // Index
          if(event.equals("GET / HTTP/1.1")) {
            // ...
            client.close();
          }
  
          // Authenticate
          if(event.charAt(0) == '0') {
            String client_token = Arrays.copyOfRange(byte[] event, int 1, 33);
  
            // I'm gonna add the MySQL Queries later
  
            // if session id found on table
            String client_google = "000000000000000000000"; // MySQL
            client.session = client_token; // -&gt; Token received from client. (?)
            client.gid = client_google; // -&gt; Google+ Profile (?)
            // **How do I set variables to the current client?**
          }
  
          // Sync settings
          if(event.charAt(0) == '0') {
            // ...
            // access non static variable from here
            System.out.println(client.session); // (?)
            System.out.println(client.gid); // (?)
          }
  
          // More events
        }
        catch(Exception e) {
          System.out.println(e);
        }
      }
    }
  
    // End.
  }
  </code></pre>
  
  <p>Thanks.</p>