buenos dias estoy intentando hacer una conexión por sockets desde php y haciendo de servidor con java. a continuacion les describo mas o menos lo que sucede:
FLUJO:
1 - Servidor Inicia
2- Cliente crea la conexion socket.
3- Cliente abre la conexion socket.
4 - Servidor recibe conexion;
5 - Cliente Envia mensaje "ping".
6- al intentar leer el Bufferd el servidor se queda esperando "no se que"
(en la linea 42 del codigo java) .
(Este es mi problema)7. el cliente se le agota el tiempo de espera y se genera excepción.
8. justo al cerrarse la conexión por el tiempo agotado el servidor lee el mensaje "ping".
Servidor Java:
package modelo.conexion;
import java.io.*;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Servidor
extends Thread {
private static Servidor instance;
public static final int PORT = 9901;
public static boolean on = true;
private Servidor() {
}
@Override
public void run() {
try {
// Create the server socket
while (on) {
// Wait for a connection
System.
out.
println("Servidor a la escucha..."); clientSocket = serverSocket.accept();
// get input and output streams
// PrintWriter output = new PrintWriter (clientSocket.getOutputStream(),true);
//read data json
String data
= input.
readLine();
//output.write(data);
output.writeBytes("OK");
output.flush();
clientSocket.close();
}
Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ioe);
}
}
public static synchronized Servidor getInstance() {
if (instance == null) {
instance = new Servidor();
instance.run();
}
return instance;
}
}
Codigo Cliente PHP:
<?php
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$delimitador = "\n\n"; // -------- ESTA ES LA SOLUCION --------
$mensaje = "ping".$delimitador;
}
}
?>