

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

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

public class commande_server 
{

	public static void main(String[] args) 
	{



					ServerSocket ss = null;

					try {

						ss = new ServerSocket(8081);

						//ss.setSoTimeout(10000);

						//accept connections

						System.out.println("Server started. Listening to the port 4444");
						Socket s = ss.accept();
						System.out.println("Connection detected");
						BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
						BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

						//receive a message
						String incomingMsg = in.readLine() + System.getProperty("line.separator");
						System.out.println("received: " + incomingMsg);

						//send a message

						String outgoingMsg = "goodbye from port " + TCP_SERVER_PORT + System.getProperty("line.separator");
						out.write(outgoingMsg);
						out.flush();
						System.out.println("sent: " + outgoingMsg);


						
						//SystemClock.sleep(5000);

						s.close();

					} catch (InterruptedIOException e) {

						//if timeout occurs

						e.printStackTrace();

					} catch (IOException e) {

						e.printStackTrace();

					} finally {

						if (ss != null) {

							try {

								ss.close();

							} catch (IOException e) {

								e.printStackTrace();

							}

						}

					}
					
		}			
}
