Pessoal, boa tarde!
Preciso de uma ajuda, estou montando um servidor , consigo enviar uma informação para ele , porém, não consigo receber resposta do mesmo.
Como eu faria esse retorno do meu servidor java?
import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Server {
private int porta;
public Server(int porta){
this.porta=porta;
}
public void setServer() throws IOException, InterruptedException{
String sProce="";
String sFimTarefa="";
String capitalized;
String clientSentence;
for(;;){
String strFileContentes = "";
ServerSocket servidor = new ServerSocket(this.porta);
System.out.println("Hefesto ------- 1.0.0");
System.out.println("Porta de conexão aberta");
Socket cliente = servidor.accept();
System.out.println("Conexão remota feita pelo cliente" +
cliente.getInetAddress().getHostAddress());
BufferedInputStream in = new BufferedInputStream(cliente.getInputStream());
byte[] contentes = new byte['?'];
int byteread = 0;
while ((byteread = in.read(contentes)) != -1)
{
strFileContentes = strFileContentes + new String(contentes, 0, byteread);
strFileContentes = strFileContentes.replaceAll("(\\r|\\n)", "");
}
Runtime runtime = Runtime.getRuntime();
int op = Integer.parseInt(strFileContentes);
if (op == 1) {
try
{
Process p1 = runtime.exec("cmd /c start C:\\Users\\diego.silva\\Desktop\\Server\\ADM.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
} else if (op == 2) {
try
{
Process p1 = runtime.exec("cmd /c start E:\\Testes_Automaticos\\GRUPOA.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
} else if (op == 3) {
try
{
Process p1 = runtime.exec("cmd /c start E:\\Testes_Automaticos\\GRUPOB.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
} else if (op == 4) {
try
{
Process p1 = runtime.exec("cmd /c start E:\\Testes_Automaticos\\IrisWEb.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
} /*else if (op == 5) {
try
{
Process p1 = runtime.exec("cmd /c start E:\\Testes_Automaticos\\WriteMonitoria.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
} else if (op == 6) {
try
{
Process p1 = runtime.exec("cmd /c start E:\\Testes_Automaticos\\killProcess.bat");
InputStream is = p1.getInputStream();
int i = 0;
while ((i = is.read()) != -1) {
System.out.print((char)i);
}
}
catch (IOException ioException)
{
System.out.println(ioException.getMessage());
}
}*/ else {
System.out.println("Informação Invalida!!");
}
// PrintStream saida = new PrintStream(cliente.getOutputStream());
servidor.close();
cliente.close();
}
}
}