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

public class commande
{
   public static void main(String argv[]) throws Exception
      {
         String clientSentence;
         String capitalizedSentence;
         ServerSocket welcomeSocket = new ServerSocket(8081);

         while(true)
         {
            Socket connectionSocket = welcomeSocket.accept();
            BufferedReader inFromClient =
               new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
            //DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
            clientSentence = inFromClient.readLine();
            System.out.println("Received: " + clientSentence);
            //capitalizedSentence = clientSentence.toUpperCase() + '\n';
            //outToClient.writeBytes(capitalizedSentence);
         }
      }
} 
/*
- See more at: https://systembash.com/a-simple-java-tcp-server-and-tcp-client/#sthash.w31im8rG.dpuf

try{
 
ServerSocket ss = null;
 
// Initialize Server Socket to listen to its opened port
ss = new ServerSocket(5555);
 
// Accept any client connection
Socket s = ss.accept();
 
// Initialize Buffered reader to read the message from the client
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
 
// Get incoming message
String incomingMessage = in.readLine() + System.getProperty("line.separator");
 
// Use incomingMessage as required
System.out.print(incomingMessage);
 
// Close input stream
in.close();
 
// Close Socket
s.close();
 
// Close server socket
ss.close();
 
}
catch(Exception ex){
//:TODO Handle exceptions
}
*/




class ClientAsyncTask extends AsyncTask<String, Void, String> 
		{
			  @Override
			  protected String doInBackground(String... params) 
			  {
				  String result = null;
			   
				  try {
					  	Socket socket = new Socket(params[0], Integer.parseInt(params[1]));
					  	//Get the input stream of the client socket
					  	InputStream is = socket.getInputStream();
					  	//Get the output stream of the client socket
					  	PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
					  	//Write data to the output stream of the client socket
					  	out.println(params[2]); 
					  	//Buffer the data coming from the input stream
					  	BufferedReader br = new BufferedReader( new InputStreamReader(is));
					  	//Read data in the input buffer
					  	result = br.readLine();
					  	//Close the client socket
					  	socket.close();
					  	message.setText(result);
				  } 
				  
				  catch (NumberFormatException e)
				  {
					  e.printStackTrace();
				  } 
				  
				  catch (UnknownHostException e) 
				  {
					  e.printStackTrace();
				  } 
				  
				  catch (IOException e)
				  {
					  e.printStackTrace();
				  }
				  return result;
			  }
			  
			  @Override
			  protected void onPostExecute(String s)
			  {
				  //Write server message to the text view
				   message.setText(s);
			  }

 
		}
 