Hi all,
I have a Java socket client, when a run it I got java.net.SocketException:
Connection reset. here is my code.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
*
* @author Administrator
*/
public class socketEnee {
public String EnviaTrama(String Todo) throws IOException {
String respuestaEnee = "";
PrintWriter out1 = null;
BufferedReader in = null;
System.out.println("Trama desde Cliente = " + Todo);
SocketAddress sockaddr = new InetSocketAddress("63.245.8.247", 84);
Socket echoSocket = null;
try {
echoSocket = new Socket();
echoSocket.connect(sockaddr);
out1 = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost.");
respuestaEnee = "998Don't know about host: localhost.iSeries";
return respuestaEnee;
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection
to: localhost.");
respuestaEnee = "999No hay comunicacion con el iSeries***";
return respuestaEnee;
}
// BufferedReader stdIn = new BufferedReader(
// new InputStreamReader(System.in));
String userInput = (Todo);
out1.println(userInput);
out1.flush();
try {
respuestaEnee = in.readLine();
} catch (SocketTimeoutException e) {
System.out.println("Socket Timeout ERROR");
respuestaEnee = "998Error de Comunicaciones con el proveedor :"
+ e.getMessage();
return respuestaEnee;
}
System.out.println("Trama de Respuesta = " + respuestaEnee);
out1.close();
in.close();
// stdIn.close();
echoSocket.close();
return respuestaEnee;
}
public static void main(String[] args) throws IOException {
socketEnee soc = new socketEnee();
String resp = soc.EnviaTrama("10042601");
System.out.println("Respuesta : "+resp);
}
}
can somebody help me.
Thank you in advance.
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.