Java Server empfängt php inhalt nicht

Jinairu

Mitglied
Hi Leute,
ich stehe aktuell vor dem Problem, dass mein JavaServer nicht alles ausliest, was er soll.
Ich habe einen Serversocket der auf Port 8080 lauscht.
Das steht im Post von der PhP seite:
PHP:
<?php

$action = $_GET['action'];
$hash = $_GET['hash'];
$xml = $_POST['xml'];
$md5sum = $_POST['md5sum'];

?>
ich habs per byte[] probiert, readline und einigen anderen sachen.
Jedes mal, wenn er etwas liest und ausgibt, ist es nur das:
Ausgabe.JPG
Irgendwie komm ich nicht an den Inhalt ran.
Hat irgendwer eine Idee?`
Vielen Dank und Grüße,
Jin

Ps. Hier sind 2 Versuche als Code
Java:
public class Start {
	public static void main(String[] args) throws IOException {
		
		// ServerSocket serverSocket = null;
		
		 //try {
		// serverSocket = new ServerSocket(8080);
		//} catch (IOException ex) {
		// System.out.println("Can't setup server on this port number. ");
		// }
		 
		//
		// Socket socket = null;
		// InputStream is = null;
		// FileOutputStream fos = null;
		// BufferedOutputStream bos = null;
		// int bufferSize = 0;
		//
		// try {
		// socket = serverSocket.accept();
		// } catch (IOException ex) {
		// System.out.println("Can't accept client connection. ");
		// }
		//
		// try {
		// is = socket.getInputStream();
		//
		// bufferSize = socket.getReceiveBufferSize();
		// System.out.println("Buffer size: " + bufferSize);
		// } catch (IOException ex) {
		// System.out.println("Can't get socket input stream. ");
		// }
		//
		// try {
		// String tmpDirectoryOp = System.getProperty("java.io.tmpdir");
		// File tmpDirectory = new File(tmpDirectoryOp);
		// File fstream = File.createTempFile("tmpDirectory", ".flv",
		// tmpDirectory);
		// System.out.println("created");
		// fos = new FileOutputStream(fstream);
		//
		// fstream.deleteOnExit();
		//
		// bos = new BufferedOutputStream(fos);
		//
		// } catch (FileNotFoundException ex) {
		// System.out.println("File not found. ");
		// }
		//
		//
		// bos.flush();
		// bos.close();
		// is.close();
		// socket.close();
		// serverSocket.close();
		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					Thread.sleep(30000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.exit(0);
			}
		}).start();
		// }
		try {
			ServerSocket ssock = new ServerSocket(8080);
			System.out.println("Port offen");
			Socket sock = ssock.accept();
			System.out.println("Connection done");
			OneConnection client = new OneConnection(sock);
			String s = client.getRequest();
			ssock.close();
			System.out.print("Alles ausgegeben");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class OneConnection {
	Socket sock;
	BufferedReader in = null;
	DataOutputStream out = null;

	public OneConnection(Socket sock) throws IOException {
		this.sock = sock;
		in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
		out = new DataOutputStream(sock.getOutputStream());
	}

	public String getRequest() throws IOException {

		String s = "";
		while (((s = in.readLine()) != null) && (!(in.equals("")))) {
			System.out.println(s);
		}
		return s;
	}
}
 
Zuletzt bearbeitet:
Geschafft,
ich bin mir nicht sicher, woran es gelegen hat, aber eventuell eine Mischung aus Bufferedreader und dem socket.inputstream? Nur mit dem Bufferedreader hats irgendwie nicht geklappt. Nun gehts 🙂
Vielleicht hilft das noch mal jemandem.

Grüße,
Jin

Java:
public class Start {
	public static void main(String[] args) throws IOException {
		try {
			ServerSocket ssock = new ServerSocket(8080);
			System.out.println("Port offen");
			Socket sock = ssock.accept();
			System.out.println("Verbindung steht");
			OneConnection client = new OneConnection(sock);
			String xmlFile = client.getRequest();
			System.out.println(xmlFile);
			ssock.close();
			sock.close();
			System.out.print("Alles ausgegeben");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class OneConnection {
	Socket sock;

	public OneConnection(Socket sock) throws IOException {
		this.sock = sock;
	}

	public String getRequest() throws IOException {

		byte[] content = new byte[20000];
		String finalString = "";
		do {
			sock.getInputStream().read(content);
//um den url content umzuwandeln 
			finalString += URLDecoder.decode(new String(content, "UTF-8"), "UTF-8");
		} while (sock.getInputStream().available() > 0);
		return finalString;
	}
}
 

Zurück
Oben