Package org.sentinel.servers.helloworld

Source Code of org.sentinel.servers.helloworld.Client

package org.sentinel.servers.helloworld;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import org.sentinel.client.ClientException;

public class Client extends org.sentinel.client.Client
{

    @Override
    public byte[] sendRawRequest(byte[] data) throws ClientException
    {
        try {
            // this is a really simple client, we send the data to the server even though it ignores
            // it
            OutputStream out = socket.getOutputStream();
            out.write(data);
            out.flush();
           
            // now read the result, even though we know what the result is going to be
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String output = "", inputLine;
            while((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
                output += inputLine + "\n";
            }
           
            return output.getBytes();
        }
        catch(IOException ex) {
            throw new ClientException(ex.getMessage());
        }
    }

}
TOP

Related Classes of org.sentinel.servers.helloworld.Client

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.