0
我有一個Socket
在Java中,併發送一個DatagramPacket
,我需要從PHP頁面讀取,然後將其寫入文件,但我找不到一種方法來做到這一點。如何獲得datagrampacket在PHP
這是Java的插座代碼:
private void openSocket(){
try {
client = new DatagramSocket();
System.out.println(" Socket client açıldı.. ");
} catch (Exception e) {
System.out.println(" PosyByte : Open Socket Hata " + e.toString());
}
}
private InetAddress getIpaddress(String adress){
try {
InetAddress ipaddress = InetAddress.getByName(adress);
return ipaddress;
} catch (Exception e) {
System.out.println(" PosyByte : getIpaddress Hata! " + e.toString());
return null;
}
}
private DatagramPacket createDatagramPacket(byte[] buf , int length , InetAddress ipadress , int port){
DatagramPacket dp = new DatagramPacket(buf, length, ipadress, port);
return dp;
}
private void sendDataOnSocket (DatagramPacket udp){
try {
client.send(udp);
} catch (IOException ex) {
System.out.println(" PosyByte : SendDataonSocket Hata! " + ex.toString());
}catch (Exception e){
System.out.println(" PosyByte : SendDataonSocket Hata! " + e.toString());
}
}
private void closeSocket(){
client.close();
System.out.println(" Socket client kapandı.. ");
}
這可能有助於閱讀:http://www.phpgangsta.de/udp-nachrichten-versenden-und-empfangen(這是德語,但有很好的例子,說明自己)在文章的底部是什麼我想你正在尋找。 – Fildor
謝謝,我要試一試 – Acablack