title: TCP/IP Sending request and getting response
body: <p>I am Working on <code>TCP/IP</code> in Java. First, I read <code>TCP/IP</code> and understand how it's working.<br>
  <strong>What i Need:-</strong><br>
  Ok,  Now i want to implement it in java.  I am trying to Send some input in request to specific <code>port/IP</code> from my IP. and need to get response.<br>
  I don't understand how to implement it.<br>
   Here is my Input:  </p>
  
  <pre><code>Destination IP  
  Destination Port
  Input(String or Anything)    
  </code></pre>
  
  <p>Here is my code which i use for Client.   </p>
  
  <pre><code>try {
          socket = new Socket("localhost", port);
      }
      catch(Exception e) {
          System.out.println("Error connectiong to server:" + e);
          return;
      }
      System.out.println("Connection accepted " +
              socket.getInetAddress() + ":" +
              socket.getPort());
  
      /* Creating both Data Stream */
      try
      {
          Sinput  = new ObjectInputStream(socket.getInputStream());
          Soutput = new ObjectOutputStream(socket.getOutputStream());
      }
      catch (IOException e) {
          System.out.println("Exception creating new Input/output Streams: " + e);
          return;
      }
      // now that I have my connection
      String test = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
      // send the string to the server
      System.out.println("Client sending \"" + test + "\" to serveur");
      try {
          Soutput.writeObject(test);
          Soutput.flush();
      }
      catch(IOException e) {
          System.out.println("Error writting to the socket: " + e);
          return;
      }
      // read back the answer from the server
      String response;
      try {
          response = (String) Sinput.readObject();
          System.out.println("Read back from server: " + response);
      }
      catch(Exception e) {
          System.out.println("Problem reading back from server: " + e);
      }
  
      try{
          Sinput.close();
          Soutput.close();
      }
  </code></pre>
  
  <p>Please give me some hint or reference.</p>