1,rtx服务器端有很多端口,二次发的程序与这些打开的端口交互。打开端口的方法在rtx服务管理器中,默认http服务未启用。需要手动启用http端口如下:
如果打开rtx服务器没有启用http的8012端口,则会报错:java.net.socket.ConnectException :connection refused
2,采用java的httpclient方式做信息交互。
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class SendRTXMessage {
/**
* RTX发送消息提醒
* @param receivers String 接收人(多个接收人以逗号分隔)
* @param title String 消息标题
* @param msg String 消息内容
* @param type String 0:普通消息 1:紧急消息
* @param delayTime String 显示停留时间(毫秒) 0:为永久停留(用户关闭时才关闭)
* @return int 0:操作成功 非0:操作不成功
*/
public int SendRTXNotify(String receivers,String title,String msg,String type,String delayTime)throws Exception{
int iRet= -1;
String rtxHost = CommConstant.RTX_HOST;
StringBuffer strURL = new StringBuffer("http://" + rtxHost + ":8012/sendnotify.cgi");//?msg=hello&receiver=admin";
try
{
strURL.append("?msg=").append(URLEncoder.encode(msg,"gb2312"))
.append("&receiver=").append(URLEncoder.encode(receivers,"gb2312"))
.append("&title=").append(URLEncoder.encode(title,"gb2312"));
java.net.URL url = new URL(strURL.toString());
HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream()));
while ((s=reader.readLine())!=null){
result += s;
}
if (result.indexOf("操作成功")>-1) iRet = 0;
}
catch(Exception e)
{
System.out.println("系统出错"+e);
}
return iRet;
}
}
3,windows下端口占用情况查看方法如下:
命令:netstat -aon|findstr [端口号];tasklist|findstr [PID]