?? telephoneteller.java
字號:
package com.ideas.communicate;
import java.net.*;
import java.io.*;
import com.ideas.util.Configuration;
/**
*Tcp Protocol client
*/
public class TelephoneTeller {
// private Socket clientsock;
public static void send(String content) {
Socket clientsock = null;
try {
InetAddress target = InetAddress.getByName(Configuration.
TelephoneTellerListenerAddress);
clientsock = new Socket(target, Configuration.TelephoneTellerListenerPort);
}
catch (Exception e) {
System.err.println("電話報警程序不能連接主機:" +
Configuration.TelephoneTellerListenerAddress + "/" +
Configuration.TelephoneTellerListenerPort);
return;
}
try {
DataOutputStream dos = new DataOutputStream(clientsock.getOutputStream());
dos.write(content.getBytes());
dos.close();
clientsock.close();
//System.out.println("電話報警消息發送成功,消息內容:"+content);
}
catch (Exception e) {
System.err.println("報警消息發送失敗");
e.printStackTrace();
}
}
public static void main(String[] args) {
TelephoneTeller.send("{192.168.2.117}{rs6000}{101}{102}{103}{104}{201}{301}");
}
}
/*UDP protocol client
public class TelephoneTeller {
private DatagramSocket teller;
public TelephoneTeller() {
try {
teller = new DatagramSocket();
}
catch (SocketException se) {
se.printStackTrace();
}
}
public boolean send(String destaddress, int destport, String content) {
boolean success = false;
try {
InetAddress target = InetAddress.getByName(destaddress);
byte[] buffer;
buffer = content.getBytes();
DatagramPacket dgp = new DatagramPacket(buffer, buffer.length, target,
10000);
dgp.setPort(destport);
teller.send(dgp);
success = true;
}
catch (UnknownHostException uhe) {
System.err.println("沒有找到" + destaddress + "對應的主機!\n");
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return success;
}
public static void main(String args[]) {
if (new TelephoneTeller().send("192.168.2.63", 5000, "Hello world!")) {
System.out.println("success!");
}
}
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -