0
我試圖在PHP套接字和JAVA套接字之間傳遞簡單的消息。 php套接字成功發送數據並等待Java服務器響應。但另一方面,Java服務器的套接字仍在等待來自PHP的消息。PHP套接字發送數據,但Java套接字沒有收到
這裏是Java代碼:
ServerSocket s = new ServerSocket(4280);
Socket sock = s.accept();
System.out.println("Connected");
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
System.out.println("Reading");
String str = br.readLine();
System.out.println("Writing");
bw.write(str);
輸出:
連接
閱讀
這裏是PHP代碼:
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($socket, "localhost", 4280);
socket_write($socket, "Hello");
echo socket_read($socket, 10);
socket_write($socket, "Lelo");
echo socket_read($socket, 10);
輸出:
瀏覽器:等待本地主機