title: Connecting to a server via Java Socket and ServerSocket Class
body: <p>I have what will hopefully be a very simple question. I'm writing a series of java programs which utilize cryptographic functions like RSA, El Gamal, etc for a security class. so that a client (Alice) and server (Bob) can communicate securely. But, I have no clue how to connect to a server on my computer using java. I've used MAMP to connect to a web server where I've written code in PHP/SQL, but I don't know how it would work using Java. Specifically, the starter files I was given all use the Java class Socket and ServerSocket like so:</p>
  
  <pre><code>String host = "localhost";
  int port = 7999;
  Socket s = new Socket(host, port);
  ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
  </code></pre>
  
  <p>And for the server (Bob):</p>
  
  <pre><code>int port = 7999;
  ServerSocket s = new ServerSocket(port);
  Socket client = s.accept();
  ObjectInputStream is = new ObjectInputStream(client.getInputStream());
  </code></pre>
  
  <p>What would I do on my computer to connect to a server via this code?</p>