Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  TCPClient
Language: JAVA
Code:
/*Kurose, J.; Ross, K. Redes de Computadores e Internet: uma nova abordagem. Boston: Addison-Wesley, 3a Ed. */

import java.io.*;
import java.net.*;

public class TCPClient {

     /**
      * @param args
      */
     public static void main(String[] args) throws Exception {
          
          String sentence;
          String modifiedSentence;
          
          BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
          
          Socket clientSocket = new Socket("localhost", 6789);
          DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
          
          BufferedReader inFromServer = 
               new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
          
          sentence = inFromUser.readLine();
          outToServer.writeBytes(sentence + "\n");
          
          modifiedSentence = inFromServer.readLine();
          
          System.out.println("From Server: " + modifiedSentence);
          
          clientSocket.close();

     }

}
Comments: