Code example for Socket

Methods: getInputStream, getOutputStream, setKeepAlive

0
    private BufferedWriter os;
    private BufferedReader is;
     
    public boolean Connect(String host, int port) {
        try { 
                socket = new Socket(host, port);
                socket.setKeepAlive(true);
                System.out.println(socket);
                os = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                return true; 
            }  
        catch (Exception e) {
            System.err.println("Could not connect: " + e);
        } 
        return false; 
     } 
     
    public void sendSpeechCommand(String command) {
        try { 
                os.write(command);