开发者

How to write a code to notify on XML file changes?

I am writing a XML gui editor using java, which edits the xml file and there are programs which would read that xml file and act according the changes immediately. For that purpose, I need to invoke an <ip-address>:<portnumber>, I need to send a small amount of textual data "/n" too. To be precise I need to alert a particular ip adress that some changes has been made to the xml file, and that it should re-read it, so that the changes can take affect. Now any ideas as to 开发者_如何学运维how to go about it?


The easiest solution is to implement a small UDP or TCP/IP based solution. Unless the other system already defines an API telling you how to send a notification.

Java based client/server are described on several locations, here's a SO question that asks for a tutorial. For this question, I suggest you look at the existing API and/or the tutorial, for detailed answers we need more input.


You can start with this snippet - but absolutely no guarantee that it actually works in your environment:

Socket socket = new Socket("localhost", 12345);  // replace with real ip/port
Writer out = new PrintWriter(socket.getOutputStream(), true);
out.println();                                   // this sends the '\n'
out.close();
socket.close();

You'll have to add some exception handling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜