我在Java中有Socket
并发送一个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ı.. ");
}
答案 0 :(得分:0)
看看我在PHP中编写的SA-MP (San Andreas Multiplayer) API,它发送和接收UDP(数据报)数据包。看一下来源可能对你有所帮助。
我也是wrote one in Java,因此您可以比较差异。