1
我嘗試並未能在PHP
和Java
之間創建一個橋接。使用我的方法,它可以發送一個字符串,但服務器在讀取數據後關閉。Java ServersSocket在讀取後關閉
這是我在Java
類:
public class Server {
private static BufferedReader inputstream;
private static BufferedWriter outputstream;
private static ServerSocket server;
public static void main(String[] args){
System.out.println("Server gestartet");
createServer();
}
private static void createServer() {
try {
server = new ServerSocket(6666);
Socket client = server.accept();
inputstream = new BufferedReader(new InputStreamReader(client.getInputStream()));
outputstream = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
String temp = null;
while((temp = inputstream.readLine()) != null){
System.out.println(temp);
}
} catch (IOException e) {
e.printStackTrace();
}
try {
inputstream.close();
outputstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
這就是我如何從PHP發送字符串:
<?php
$socket = fsockopen('localhost', 6666, $errno, $errstr, 30);
if(!$socket){
echo("$errno <br> $errstr");
}
fwrite($socket, "Hello its me\n");
fclose($socket);
?>
事先非常感謝,我希望你能幫助我:)