我有一个Socket
Java 并发送一个DatagramPacket
我需要从 PHP 页面读取的内容,然后将其写入文件,但我找不到办法。
这是 Java 中的 Socket 代码:
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ı.. ");
}